You can subscribe to this list here.
2000 |
Jan
(11) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(8) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(145) |
Nov
(352) |
Dec
(329) |
2002 |
Jan
(461) |
Feb
(533) |
Mar
(632) |
Apr
(363) |
May
(619) |
Jun
(324) |
Jul
(109) |
Aug
(247) |
Sep
(167) |
Oct
(215) |
Nov
(115) |
Dec
(262) |
2003 |
Jan
(568) |
Feb
(537) |
Mar
(760) |
Apr
(493) |
May
(500) |
Jun
(284) |
Jul
(178) |
Aug
(180) |
Sep
(135) |
Oct
(230) |
Nov
(266) |
Dec
(175) |
2004 |
Jan
(121) |
Feb
(294) |
Mar
(222) |
Apr
(172) |
May
(162) |
Jun
(105) |
Jul
(93) |
Aug
(151) |
Sep
(136) |
Oct
(62) |
Nov
(74) |
Dec
(178) |
2005 |
Jan
(179) |
Feb
(288) |
Mar
(153) |
Apr
(138) |
May
(195) |
Jun
(39) |
Jul
(62) |
Aug
(41) |
Sep
(15) |
Oct
(365) |
Nov
(130) |
Dec
(199) |
2006 |
Jan
(235) |
Feb
(92) |
Mar
(262) |
Apr
(250) |
May
(345) |
Jun
(513) |
Jul
(587) |
Aug
(210) |
Sep
(216) |
Oct
(200) |
Nov
(188) |
Dec
(115) |
2007 |
Jan
(259) |
Feb
(182) |
Mar
(217) |
Apr
(109) |
May
(161) |
Jun
(205) |
Jul
(291) |
Aug
(176) |
Sep
(185) |
Oct
(190) |
Nov
(208) |
Dec
(182) |
2008 |
Jan
(141) |
Feb
(193) |
Mar
(219) |
Apr
(112) |
May
(233) |
Jun
(218) |
Jul
(149) |
Aug
(338) |
Sep
(291) |
Oct
(143) |
Nov
(131) |
Dec
(152) |
2009 |
Jan
(266) |
Feb
(178) |
Mar
(168) |
Apr
(167) |
May
(198) |
Jun
(282) |
Jul
(383) |
Aug
(341) |
Sep
(153) |
Oct
(214) |
Nov
(164) |
Dec
(278) |
2010 |
Jan
(430) |
Feb
(300) |
Mar
(214) |
Apr
(198) |
May
(271) |
Jun
(321) |
Jul
(144) |
Aug
(208) |
Sep
(275) |
Oct
(287) |
Nov
(218) |
Dec
(153) |
2011 |
Jan
(172) |
Feb
(172) |
Mar
(121) |
Apr
(62) |
May
(23) |
Jun
(155) |
Jul
(120) |
Aug
(252) |
Sep
(170) |
Oct
(206) |
Nov
(356) |
Dec
(300) |
2012 |
Jan
(412) |
Feb
(313) |
Mar
(419) |
Apr
(153) |
May
(194) |
Jun
(226) |
Jul
(115) |
Aug
(143) |
Sep
(223) |
Oct
(173) |
Nov
(121) |
Dec
(143) |
2013 |
Jan
(156) |
Feb
(109) |
Mar
(146) |
Apr
(82) |
May
(65) |
Jun
(52) |
Jul
(55) |
Aug
(347) |
Sep
(65) |
Oct
(95) |
Nov
(85) |
Dec
(37) |
2014 |
Jan
(12) |
Feb
(51) |
Mar
(31) |
Apr
(97) |
May
(60) |
Jun
(32) |
Jul
(35) |
Aug
(47) |
Sep
(16) |
Oct
(36) |
Nov
(55) |
Dec
(90) |
2015 |
Jan
(34) |
Feb
(65) |
Mar
(13) |
Apr
(13) |
May
(49) |
Jun
(10) |
Jul
(23) |
Aug
(96) |
Sep
(78) |
Oct
(38) |
Nov
(41) |
Dec
(126) |
2016 |
Jan
(29) |
Feb
(38) |
Mar
(21) |
Apr
(12) |
May
(45) |
Jun
(53) |
Jul
(40) |
Aug
(69) |
Sep
(60) |
Oct
(11) |
Nov
(19) |
Dec
(2) |
2017 |
Jan
(28) |
Feb
(17) |
Mar
(57) |
Apr
(4) |
May
(15) |
Jun
(60) |
Jul
(21) |
Aug
(5) |
Sep
(6) |
Oct
(34) |
Nov
(17) |
Dec
(28) |
2018 |
Jan
(15) |
Feb
(7) |
Mar
(13) |
Apr
(7) |
May
(2) |
Jun
(6) |
Jul
(10) |
Aug
(15) |
Sep
(6) |
Oct
|
Nov
|
Dec
|
2019 |
Jan
(2) |
Feb
(2) |
Mar
(9) |
Apr
(5) |
May
|
Jun
(6) |
Jul
(4) |
Aug
(35) |
Sep
(1) |
Oct
(6) |
Nov
(1) |
Dec
(18) |
2020 |
Jan
(1) |
Feb
|
Mar
(141) |
Apr
(196) |
May
(41) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
(27) |
Oct
(2) |
Nov
(4) |
Dec
(25) |
2021 |
Jan
(8) |
Feb
(1) |
Mar
(46) |
Apr
(48) |
May
|
Jun
(9) |
Jul
(1) |
Aug
|
Sep
(5) |
Oct
(3) |
Nov
(10) |
Dec
(7) |
2022 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
(24) |
Jul
(7) |
Aug
(7) |
Sep
(13) |
Oct
(7) |
Nov
(1) |
Dec
(2) |
2023 |
Jan
(11) |
Feb
(4) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
(13) |
Sep
(32) |
Oct
(10) |
Nov
(6) |
Dec
|
2024 |
Jan
|
Feb
(8) |
Mar
(4) |
Apr
(3) |
May
(22) |
Jun
|
Jul
(11) |
Aug
(8) |
Sep
|
Oct
(9) |
Nov
|
Dec
|
2025 |
Jan
|
Feb
(2) |
Mar
(16) |
Apr
(5) |
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <dal...@us...> - 2022-10-28 21:38:57
|
Revision: 25614 http://sourceforge.net/p/jedit/svn/25614 Author: daleanson Date: 2022-10-28 21:38:54 +0000 (Fri, 28 Oct 2022) Log Message: ----------- fixing comment processing and tests. Modified Paths: -------------- plugins/Beauty/trunk/ant_java_test.xml plugins/Beauty/trunk/ant_json_test.xml plugins/Beauty/trunk/build.xml plugins/Beauty/trunk/src/beauty/options/BeautifierOptionPane.java plugins/Beauty/trunk/src/beauty/parsers/bsh/JavaCharStream.java plugins/Beauty/trunk/src/beauty/parsers/java/JavaCharStream.java plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaLexer.g4 plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java plugins/Beauty/trunk/src/beauty/parsers/javacc/JavaCharStream.java plugins/Beauty/trunk/test/resource/before/test1.json plugins/Beauty/trunk/test/test_files/java/after/AllInOne11.java plugins/Beauty/trunk/test/test_files/java/after/AllInOne17.java plugins/Beauty/trunk/test/test_files/java/after/AllInOne8.java plugins/Beauty/trunk/test/test_files/java/after/BasicClass.java plugins/Beauty/trunk/test/test_files/java/after/BasicClass3.java plugins/Beauty/trunk/test/test_files/java/after/BlockTest.java plugins/Beauty/trunk/test/test_files/java/after/Comments.java plugins/Beauty/trunk/test/test_files/java/after/Comments2.java plugins/Beauty/trunk/test/test_files/java/after/Element1.java plugins/Beauty/trunk/test/test_files/java/after/EnumTest.java plugins/Beauty/trunk/test/test_files/java/after/IF_PERMITS.java plugins/Beauty/trunk/test/test_files/java/after/Ids.java plugins/Beauty/trunk/test/test_files/java/after/ImportsAndAnnos.java plugins/Beauty/trunk/test/test_files/java/after/ManyStringsConcat.java plugins/Beauty/trunk/test/test_files/java/after/PatternMatching4instanceof.java plugins/Beauty/trunk/test/test_files/java/after/PatternMatching4switchExp.java plugins/Beauty/trunk/test/test_files/java/after/Pizza.java plugins/Beauty/trunk/test/test_files/java/after/Records.java plugins/Beauty/trunk/test/test_files/java/after/SealedClasses.java plugins/Beauty/trunk/test/test_files/java/after/SwitchExpressions.java plugins/Beauty/trunk/test/test_files/java/after/TextBlocks.java plugins/Beauty/trunk/test/test_files/java/after/Yield.java plugins/Beauty/trunk/test/test_files/java/after/outer.java plugins/Beauty/trunk/test/test_files/java/before/AllInOne11.java plugins/Beauty/trunk/test/test_files/java/before/Comments.java plugins/Beauty/trunk/test/test_files/java/before/PatternMatching4switchExp.java plugins/Beauty/trunk/test/test_files/java/expected/AllInOne11.java plugins/Beauty/trunk/test/test_files/java/expected/AllInOne17.java plugins/Beauty/trunk/test/test_files/java/expected/AllInOne8.java plugins/Beauty/trunk/test/test_files/java/expected/BasicClass.java plugins/Beauty/trunk/test/test_files/java/expected/BasicClass3.java plugins/Beauty/trunk/test/test_files/java/expected/BlockTest.java plugins/Beauty/trunk/test/test_files/java/expected/Comments.java plugins/Beauty/trunk/test/test_files/java/expected/Comments2.java plugins/Beauty/trunk/test/test_files/java/expected/Element1.java plugins/Beauty/trunk/test/test_files/java/expected/EnumTest.java plugins/Beauty/trunk/test/test_files/java/expected/IF_PERMITS.java plugins/Beauty/trunk/test/test_files/java/expected/Ids.java plugins/Beauty/trunk/test/test_files/java/expected/ImportsAndAnnos.java plugins/Beauty/trunk/test/test_files/java/expected/ManyStringsConcat.java plugins/Beauty/trunk/test/test_files/java/expected/PatternMatching4instanceof.java plugins/Beauty/trunk/test/test_files/java/expected/PatternMatching4switchExp.java plugins/Beauty/trunk/test/test_files/java/expected/Pizza.java plugins/Beauty/trunk/test/test_files/java/expected/Records.java plugins/Beauty/trunk/test/test_files/java/expected/SealedClasses.java plugins/Beauty/trunk/test/test_files/java/expected/SwitchExpressions.java plugins/Beauty/trunk/test/test_files/java/expected/TextBlocks.java plugins/Beauty/trunk/test/test_files/java/expected/Yield.java plugins/Beauty/trunk/test/test_files/java/expected/outer.java Modified: plugins/Beauty/trunk/ant_java_test.xml =================================================================== --- plugins/Beauty/trunk/ant_java_test.xml 2022-10-11 22:08:29 UTC (rev 25613) +++ plugins/Beauty/trunk/ant_java_test.xml 2022-10-28 21:38:54 UTC (rev 25614) @@ -1,4 +1,11 @@ <project name="java_test" default="test" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless"> + + <echo> +================================================================================ + Java Tests +================================================================================ + </echo> + <!-- ======================================================================== Target: set classpath ========================================================================= --> @@ -42,7 +49,6 @@ NOTE: THESE TESTS EXEC THE SYSTEM DIFF!!! THEY WILL FAIL IF DIFF IS NOT INSTALLED OR NOT ON THE PATH!!! - TODO: change out the echos with a fail. ======================================================================== --> <target name="test" depends="IF_PERMITS,AllInOne11,AllInOne17,AllInOne8,BasicClass,BasicClass3,BlockTest,Comments, Comments2,Element1,EnumTest,Ids,ImportsAndAnnos,ManyStringsConcat,module-info,outer,PatternMatching4instanceof, @@ -52,458 +58,482 @@ <target name="Yield" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Yield.java"/> + <arg file="./test/test_files/java/before/Yield.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Yield.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Yield.java" /> + binaryOutput="true" + input="./test/test_files/java/before/Yield.java" + output="./test/test_files/java/after/Yield.java" /> </java> <exec executable="diff" outputproperty="Yielddiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Yield.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Yield.java"/> + <arg value="./test/test_files/java/after/Yield.java"/> + <arg value="./test/test_files/java/expected/Yield.java"/> </exec> <condition property="Yield" value="true"> <equals arg1="${Yielddiff}" arg2=""/> </condition> <echo if:set="Yield">Yield passed</echo> - <echo unless:set="Yield">Yield failed: ${Yielddiff}</echo> + <fail unless:set="Yield">Yield failed: ${Yielddiff}</fail> </target> <target name="TextBlocks" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/TextBlocks.java"/> + <arg file="./test/test_files/java/before/TextBlocks.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/TextBlocks.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/TextBlocks.java" /> + binaryOutput="true" + input="./test/test_files/java/before/TextBlocks.java" + output="./test/test_files/java/after/TextBlocks.java" /> </java> <exec executable="diff" outputproperty="TextBlocksdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/TextBlocks.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/TextBlocks.java"/> + <arg value="./test/test_files/java/after/TextBlocks.java"/> + <arg value="./test/test_files/java/expected/TextBlocks.java"/> </exec> <condition property="TextBlocks" value="true"> <equals arg1="${TextBlocksdiff}" arg2=""/> </condition> <echo if:set="TextBlocks">TextBlocks passed</echo> - <echo unless:set="TextBlocks">TextBlocks failed: ${TextBlocksdiff}</echo> + <fail unless:set="TextBlocks">TextBlocks failed: ${TextBlocksdiff}</fail> </target> <target name="SwitchExpressions" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/SwitchExpressions.java"/> + <arg file="./test/test_files/java/before/SwitchExpressions.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/SwitchExpressions.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/SwitchExpressions.java" /> + binaryOutput="true" + input="./test/test_files/java/before/SwitchExpressions.java" + output="./test/test_files/java/after/SwitchExpressions.java" /> </java> <exec executable="diff" outputproperty="SwitchExpressionsdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/SwitchExpressions.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/SwitchExpressions.java"/> + <arg value="./test/test_files/java/after/SwitchExpressions.java"/> + <arg value="./test/test_files/java/expected/SwitchExpressions.java"/> </exec> <condition property="SwitchExpressions" value="true"> <equals arg1="${SwitchExpressionsdiff}" arg2=""/> </condition> <echo if:set="SwitchExpressions">SwitchExpressions passed</echo> - <echo unless:set="SwitchExpressions">SwitchExpressions failed: ${SwitchExpressionsdiff}</echo> + <fail unless:set="SwitchExpressions">SwitchExpressions failed: ${SwitchExpressionsdiff}</fail> </target> <target name="SealedClasses" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/SealedClasses.java"/> + <arg file="./test/test_files/java/before/SealedClasses.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/SealedClasses.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/SealedClasses.java" /> + binaryOutput="true" + input="./test/test_files/java/before/SealedClasses.java" + output="./test/test_files/java/after/SealedClasses.java" /> </java> <exec executable="diff" outputproperty="SealedClassesdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/SealedClasses.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/SealedClasses.java"/> + <arg value="./test/test_files/java/after/SealedClasses.java"/> + <arg value="./test/test_files/java/expected/SealedClasses.java"/> </exec> <condition property="SealedClasses" value="true"> <equals arg1="${SealedClassesdiff}" arg2=""/> </condition> <echo if:set="SealedClasses">SealedClasses passed</echo> - <echo unless:set="SealedClasses">SealedClasses failed: ${SealedClassesdiff}</echo> + <fail unless:set="SealedClasses">SealedClasses failed: ${SealedClassesdiff}</fail> </target> <target name="Records" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Records.java"/> + <arg file="./test/test_files/java/before/Records.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Records.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Records.java" /> + binaryOutput="true" + input="./test/test_files/java/before/Records.java" + output="./test/test_files/java/after/Records.java" /> </java> <exec executable="diff" outputproperty="Recordsdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Records.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Records.java"/> + <arg value="./test/test_files/java/after/Records.java"/> + <arg value="./test/test_files/java/expected/Records.java"/> </exec> <condition property="Records" value="true"> <equals arg1="${Recordsdiff}" arg2=""/> </condition> <echo if:set="Records">Records passed</echo> - <echo unless:set="Records">Records failed: ${Recordsdiff}</echo> + <fail unless:set="Records">Records failed: ${Recordsdiff}</fail> </target> <target name="Pizza" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Pizza.java"/> + <arg file="./test/test_files/java/before/Pizza.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Pizza.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Pizza.java" /> + binaryOutput="true" + input="./test/test_files/java/before/Pizza.java" + output="./test/test_files/java/after/Pizza.java" /> </java> <exec executable="diff" outputproperty="Pizzadiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Pizza.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Pizza.java"/> + <arg value="./test/test_files/java/after/Pizza.java"/> + <arg value="./test/test_files/java/expected/Pizza.java"/> </exec> <condition property="Pizza" value="true"> <equals arg1="${Pizzadiff}" arg2=""/> </condition> <echo if:set="Pizza">Pizza passed</echo> - <echo unless:set="Pizza">Pizza failed: ${Pizzadiff}</echo> + <fail unless:set="Pizza">Pizza failed: ${Pizzadiff}</fail> </target> <target name="PatternMatching4switchExp" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/PatternMatching4switchExp.java"/> + <arg file="./test/test_files/java/before/PatternMatching4switchExp.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/PatternMatching4switchExp.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/PatternMatching4switchExp.java" /> + binaryOutput="true" + input="./test/test_files/java/before/PatternMatching4switchExp.java" + output="./test/test_files/java/after/PatternMatching4switchExp.java" /> </java> <exec executable="diff" outputproperty="PatternMatching4switchExpdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/PatternMatching4switchExp.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/PatternMatching4switchExp.java"/> + <arg value="./test/test_files/java/after/PatternMatching4switchExp.java"/> + <arg value="./test/test_files/java/expected/PatternMatching4switchExp.java"/> </exec> <condition property="PatternMatching4switchExp" value="true"> <equals arg1="${PatternMatching4switchExpdiff}" arg2=""/> </condition> <echo if:set="PatternMatching4switchExp">PatternMatching4switchExp passed</echo> - <echo unless:set="PatternMatching4switchExp">PatternMatching4switchExp failed: ${PatternMatching4switchExpdiff}</echo> + <fail unless:set="PatternMatching4switchExp">PatternMatching4switchExp failed: ${PatternMatching4switchExpdiff}</fail> </target> <target name="PatternMatching4instanceof" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/PatternMatching4instanceof.java"/> + <arg file="./test/test_files/java/before/PatternMatching4instanceof.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/PatternMatching4instanceof.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/PatternMatching4instanceof.java" /> + binaryOutput="true" + input="./test/test_files/java/before/PatternMatching4instanceof.java" + output="./test/test_files/java/after/PatternMatching4instanceof.java" /> </java> <exec executable="diff" outputproperty="PatternMatching4instanceofdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/PatternMatching4instanceof.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/PatternMatching4instanceof.java"/> + <arg value="./test/test_files/java/after/PatternMatching4instanceof.java"/> + <arg value="./test/test_files/java/expected/PatternMatching4instanceof.java"/> </exec> <condition property="PatternMatching4instanceof" value="true"> <equals arg1="${PatternMatching4instanceofdiff}" arg2=""/> </condition> <echo if:set="PatternMatching4instanceof">PatternMatching4instanceof passed</echo> - <echo unless:set="PatternMatching4instanceof">PatternMatching4instanceof failed: ${PatternMatching4instanceofdiff}</echo> + <fail unless:set="PatternMatching4instanceof">PatternMatching4instanceof failed: ${PatternMatching4instanceofdiff}</fail> </target> <target name="outer" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/outer.java"/> + <arg file="./test/test_files/java/before/outer.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/outer.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/outer.java" /> + binaryOutput="true" + input="./test/test_files/java/before/outer.java" + output="./test/test_files/java/after/outer.java" /> </java> <exec executable="diff" outputproperty="outerdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/outer.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/outer.java"/> + <arg value="./test/test_files/java/after/outer.java"/> + <arg value="./test/test_files/java/expected/outer.java"/> </exec> <condition property="outer" value="true"> <equals arg1="${outerdiff}" arg2=""/> </condition> <echo if:set="outer">outer passed</echo> - <echo unless:set="outer">outer failed: ${outerdiff}</echo> + <fail unless:set="outer">outer failed: ${outerdiff}</fail> </target> <target name="module-info" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/module-info.java"/> + <arg file="./test/test_files/java/before/module-info.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/module-info.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/module-info.java" /> + binaryOutput="true" + input="./test/test_files/java/before/module-info.java" + output="./test/test_files/java/after/module-info.java" /> </java> <exec executable="diff" outputproperty="module-infodiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/module-info.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/module-info.java"/> + <arg value="./test/test_files/java/after/module-info.java"/> + <arg value="./test/test_files/java/expected/module-info.java"/> </exec> <condition property="module-info" value="true"> <equals arg1="${module-infodiff}" arg2=""/> </condition> <echo if:set="module-info">module-info passed</echo> - <echo unless:set="module-info">module-info failed: ${module-infodiff}</echo> + <fail unless:set="module-info">module-info failed: ${module-infodiff}</fail> </target> <target name="ManyStringsConcat" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/ManyStringsConcat.java"/> + <arg file="./test/test_files/java/before/ManyStringsConcat.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/ManyStringsConcat.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/ManyStringsConcat.java" /> + binaryOutput="true" + input="./test/test_files/java/before/ManyStringsConcat.java" + output="./test/test_files/java/after/ManyStringsConcat.java" /> </java> <exec executable="diff" outputproperty="ManyStringsConcatdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/ManyStringsConcat.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/ManyStringsConcat.java"/> + <arg value="./test/test_files/java/after/ManyStringsConcat.java"/> + <arg value="./test/test_files/java/expected/ManyStringsConcat.java"/> </exec> <condition property="ManyStringsConcat" value="true"> <equals arg1="${ManyStringsConcatdiff}" arg2=""/> </condition> <echo if:set="ManyStringsConcat">ManyStringsConcat passed</echo> - <echo unless:set="ManyStringsConcat">ManyStringsConcat failed: ${ManyStringsConcatdiff}</echo> + <fail unless:set="ManyStringsConcat">ManyStringsConcat failed: ${ManyStringsConcatdiff}</fail> </target> <target name="ImportsAndAnnos" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/ImportsAndAnnos.java"/> + <arg file="./test/test_files/java/before/ImportsAndAnnos.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/ImportsAndAnnos.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/ImportsAndAnnos.java" /> + binaryOutput="true" + input="./test/test_files/java/before/ImportsAndAnnos.java" + output="./test/test_files/java/after/ImportsAndAnnos.java" /> </java> <exec executable="diff" outputproperty="ImportsAndAnnosdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/ImportsAndAnnos.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/ImportsAndAnnos.java"/> + <arg value="./test/test_files/java/after/ImportsAndAnnos.java"/> + <arg value="./test/test_files/java/expected/ImportsAndAnnos.java"/> </exec> <condition property="ImportsAndAnnos" value="true"> <equals arg1="${ImportsAndAnnosdiff}" arg2=""/> </condition> <echo if:set="ImportsAndAnnos">ImportsAndAnnos passed</echo> - <echo unless:set="ImportsAndAnnos">ImportsAndAnnos failed: ${ImportsAndAnnosdiff}</echo> + <fail unless:set="ImportsAndAnnos">ImportsAndAnnos failed: ${ImportsAndAnnosdiff}</fail> </target> <target name="Ids" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Ids.java"/> + <arg file="./test/test_files/java/before/Ids.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Ids.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Ids.java" /> + binaryOutput="true" + input="./test/test_files/java/before/Ids.java" + output="./test/test_files/java/after/Ids.java" /> </java> <exec executable="diff" outputproperty="Idsdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Ids.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Ids.java"/> + <arg value="./test/test_files/java/after/Ids.java"/> + <arg value="./test/test_files/java/expected/Ids.java"/> </exec> <condition property="Ids" value="true"> <equals arg1="${Idsdiff}" arg2=""/> </condition> <echo if:set="Ids">Ids passed</echo> - <echo unless:set="Ids">Ids failed: ${Idsdiff}</echo> + <fail unless:set="Ids">Ids failed: ${Idsdiff}</fail> </target> <target name="EnumTest" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/EnumTest.java"/> + <arg file="./test/test_files/java/before/EnumTest.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/EnumTest.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/EnumTest.java" /> + binaryOutput="true" + input="./test/test_files/java/before/EnumTest.java" + output="./test/test_files/java/after/EnumTest.java" /> </java> <exec executable="diff" outputproperty="EnumTestdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/EnumTest.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/EnumTest.java"/> + <arg value="./test/test_files/java/after/EnumTest.java"/> + <arg value="./test/test_files/java/expected/EnumTest.java"/> </exec> <condition property="EnumTest" value="true"> <equals arg1="${EnumTestdiff}" arg2=""/> </condition> <echo if:set="EnumTest">EnumTest passed</echo> - <echo unless:set="EnumTest">EnumTest failed: ${EnumTestdiff}</echo> + <fail unless:set="EnumTest">EnumTest failed: ${EnumTestdiff}</fail> </target> <target name="Element1" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Element1.java"/> + <arg file="./test/test_files/java/before/Element1.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Element1.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Element1.java" /> + binaryOutput="true" + input="./test/test_files/java/before/Element1.java" + output="./test/test_files/java/after/Element1.java" /> </java> <exec executable="diff" outputproperty="Element1diff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Element1.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Element1.java"/> + <arg value="./test/test_files/java/after/Element1.java"/> + <arg value="./test/test_files/java/expected/Element1.java"/> </exec> <condition property="Element1" value="true"> <equals arg1="${Element1diff}" arg2=""/> </condition> <echo if:set="Element1">Element1 passed</echo> - <echo unless:set="Element1">Element1 failed: ${Element1diff}</echo> + <fail unless:set="Element1">Element1 failed: ${Element1diff}</fail> </target> <target name="Comments2" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Comments2.java"/> + <arg file="./test/test_files/java/before/Comments2.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Comments2.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Comments2.java" /> + binaryOutput="true" + input="./test/test_files/java/before/Comments2.java" + output="./test/test_files/java/after/Comments2.java" /> </java> <exec executable="diff" outputproperty="Comments2diff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Comments2.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Comments2.java"/> + <arg value="./test/test_files/java/after/Comments2.java"/> + <arg value="./test/test_files/java/expected/Comments2.java"/> </exec> <condition property="Comments2" value="true"> <equals arg1="${Comments2diff}" arg2=""/> </condition> <echo if:set="Comments2">Comments2 passed</echo> - <echo unless:set="Comments2">Comments2 failed: ${Comments2diff}</echo> + <fail unless:set="Comments2">Comments2 failed: ${Comments2diff}</fail> </target> <target name="Comments" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Comments.java"/> + <arg file="./test/test_files/java/before/Comments.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Comments.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Comments.java" /> + binaryOutput="true" + input="./test/test_files/java/before/Comments.java" + output="./test/test_files/java/after/Comments.java" /> </java> <exec executable="diff" outputproperty="Commentsdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Comments.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Comments.java"/> + <arg value="./test/test_files/java/after/Comments.java"/> + <arg value="./test/test_files/java/expected/Comments.java"/> </exec> <condition property="Comments" value="true"> <equals arg1="${Commentsdiff}" arg2=""/> </condition> <echo if:set="Comments">Comments passed</echo> - <echo unless:set="Comments">Comments failed: ${Commentsdiff}</echo> + <fail unless:set="Comments">Comments failed: ${Commentsdiff}</fail> </target> <target name="BlockTest" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BlockTest.java"/> + <arg file="./test/test_files/java/before/BlockTest.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BlockTest.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BlockTest.java" /> + binaryOutput="true" + input="./test/test_files/java/before/BlockTest.java" + output="./test/test_files/java/after/BlockTest.java" /> </java> <exec executable="diff" outputproperty="BlockTestdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BlockTest.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/BlockTest.java"/> + <arg value="./test/test_files/java/after/BlockTest.java"/> + <arg value="./test/test_files/java/expected/BlockTest.java"/> </exec> <condition property="BlockTest" value="true"> <equals arg1="${BlockTestdiff}" arg2=""/> </condition> <echo if:set="BlockTest">BlockTest passed</echo> - <echo unless:set="BlockTest">BlockTest failed: ${BlockTestdiff}</echo> + <fail unless:set="BlockTest">BlockTest failed: ${BlockTestdiff}</fail> </target> <target name="IF_PERMITS" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/IF_PERMITS.java"/> + <arg file="./test/test_files/java/before/IF_PERMITS.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/IF_PERMITS.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/IF_PERMITS.java" /> + binaryOutput="true" + input="./test/test_files/java/before/IF_PERMITS.java" + output="./test/test_files/java/after/IF_PERMITS.java" /> </java> <exec executable="diff" outputproperty="diff"> <arg value="-a"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/IF_PERMITS.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/IF_PERMITS.java"/> + <arg value="./test/test_files/java/after/IF_PERMITS.java"/> + <arg value="./test/test_files/java/expected/IF_PERMITS.java"/> </exec> <condition property="IF_PERMITS" value="true"> <equals arg1="${diff}" arg2=""/> </condition> <echo if:set="IF_PERMITS">IF_PERMITS passed</echo> - <echo unless:set="IF_PERMITS">IF_PERMITS failed: ${diff}</echo> + <fail unless:set="IF_PERMITS">IF_PERMITS failed: ${diff}</fail> </target> <target name="AllInOne11" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne11.java"/> + <arg file="./test/test_files/java/before/AllInOne11.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne11.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne11.java" /> + binaryOutput="true" + input="./test/test_files/java/before/AllInOne11.java" + output="./test/test_files/java/after/AllInOne11.java" /> </java> <exec executable="diff" outputproperty="AllInOne11diff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne11.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/AllInOne11.java"/> + <arg value="./test/test_files/java/after/AllInOne11.java"/> + <arg value="./test/test_files/java/expected/AllInOne11.java"/> </exec> <condition property="AllInOne11" value="true"> <equals arg1="${AllInOne11diff}" arg2=""/> </condition> <echo if:set="AllInOne11">AllInOne11 passed</echo> - <echo unless:set="AllInOne11">AllInOne11 failed: ${AllInOne11diff}</echo> + <fail unless:set="AllInOne11">AllInOne11 failed: ${AllInOne11diff}</fail> </target> <target name="AllInOne17" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne17.java"/> + <arg file="./test/test_files/java/before/AllInOne17.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne17.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne17.java" /> + binaryOutput="true" + input="./test/test_files/java/before/AllInOne17.java" + output="./test/test_files/java/after/AllInOne17.java" /> </java> <exec executable="diff" outputproperty="AllInOne17diff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne17.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/AllInOne17.java"/> + <arg value="./test/test_files/java/after/AllInOne17.java"/> + <arg value="./test/test_files/java/expected/AllInOne17.java"/> </exec> <condition property="AllInOne17" value="true"> <equals arg1="${AllInOne17diff}" arg2=""/> </condition> <echo if:set="AllInOne17">AllInOne17 passed</echo> - <echo unless:set="AllInOne17">AllInOne17 failed: ${AllInOne17diff}</echo> + <fail unless:set="AllInOne17">AllInOne17 failed: ${AllInOne17diff}</fail> </target> <target name="AllInOne8" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne8.java"/> + <arg file="./test/test_files/java/before/AllInOne8.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne8.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne8.java" /> + binaryOutput="true" + input="./test/test_files/java/before/AllInOne8.java" + output="./test/test_files/java/after/AllInOne8.java" /> </java> <exec executable="diff" outputproperty="AllInOne8diff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne8.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/AllInOne8.java"/> + <arg value="./test/test_files/java/after/AllInOne8.java"/> + <arg value="./test/test_files/java/expected/AllInOne8.java"/> </exec> <condition property="AllInOne8" value="true"> <equals arg1="${AllInOne8diff}" arg2=""/> </condition> <echo if:set="AllInOne8">AllInOne8 passed</echo> - <echo unless:set="AllInOne8">AllInOne8 failed: ${AllInOne8diff}</echo> + <fail unless:set="AllInOne8">AllInOne8 failed: ${AllInOne8diff}</fail> </target> <target name="BasicClass" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BasicClass.java"/> + <arg file="./test/test_files/java/before/BasicClass.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BasicClass.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BasicClass.java" /> + binaryOutput="true" + input="./test/test_files/java/before/BasicClass.java" + output="./test/test_files/java/after/BasicClass.java" /> </java> <exec executable="diff" outputproperty="BasicClassdiff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BasicClass.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/BasicClass.java"/> + <arg value="./test/test_files/java/after/BasicClass.java"/> + <arg value="./test/test_files/java/expected/BasicClass.java"/> </exec> <condition property="BasicClass" value="true"> <equals arg1="${BasicClassdiff}" arg2=""/> </condition> <echo if:set="BasicClass">BasicClass passed</echo> - <echo unless:set="BasicClass">BasicClass failed: ${BasicClassdiff}</echo> + <fail unless:set="BasicClass">BasicClass failed: ${BasicClassdiff}</fail> </target> <target name="BasicClass3" depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BasicClass3.java"/> + <arg file="./test/test_files/java/before/BasicClass3.java"/> <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BasicClass3.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BasicClass3.java" /> + binaryOutput="true" + input="./test/test_files/java/before/BasicClass3.java" + output="./test/test_files/java/after/BasicClass3.java" /> </java> <exec executable="diff" outputproperty="BasicClass3diff"> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BasicClass3.java"/> - <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/BasicClass3.java"/> + <arg value="./test/test_files/java/after/BasicClass3.java"/> + <arg value="./test/test_files/java/expected/BasicClass3.java"/> </exec> <condition property="BasicClass3" value="true"> <equals arg1="${BasicClass3diff}" arg2=""/> </condition> <echo if:set="BasicClass3">BasicClass3 passed</echo> - <echo unless:set="BasicClass3">BasicClass3 failed: ${BasicClass3diff}</echo> + <fail unless:set="BasicClass3">BasicClass3 failed: ${BasicClass3diff}</fail> </target> </project> \ No newline at end of file Modified: plugins/Beauty/trunk/ant_json_test.xml =================================================================== --- plugins/Beauty/trunk/ant_json_test.xml 2022-10-11 22:08:29 UTC (rev 25613) +++ plugins/Beauty/trunk/ant_json_test.xml 2022-10-28 21:38:54 UTC (rev 25614) @@ -1,4 +1,11 @@ -<project name="java_test" default="test" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless"> +<project name="json_test" default="test" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless"> + + <echo> +================================================================================ + JSON Tests +================================================================================ + </echo> + <!-- ======================================================================== Target: set classpath ========================================================================= --> @@ -39,7 +46,7 @@ <equals arg1="${test1diff}" arg2=""/> </condition> <echo if:set="test1">test1 passed</echo> - <echo unless:set="test1">test1 failed: ${test1diff}</echo> + <fail unless:set="test1">test1 failed: ${test1diff}</fail> </target> <target name="test2" depends="setClasspath"> @@ -55,7 +62,7 @@ <equals arg1="${test2diff}" arg2=""/> </condition> <echo if:set="test2">test2 passed</echo> - <echo unless:set="test2">test2 failed: ${test2diff}</echo> + <fail unless:set="test2">test2 failed: ${test2diff}</fail> </target> <target name="test3" depends="setClasspath"> @@ -71,7 +78,7 @@ <equals arg1="${test3diff}" arg2=""/> </condition> <echo if:set="test3">test3 passed</echo> - <echo unless:set="test3">test3 failed: ${test3diff}</echo> + <fail unless:set="test3">test3 failed: ${test3diff}</fail> </target> <target name="test4" depends="setClasspath"> @@ -87,7 +94,7 @@ <equals arg1="${test4diff}" arg2=""/> </condition> <echo if:set="test4">test4 passed</echo> - <echo unless:set="test4">test4 failed: ${test4diff}</echo> + <fail unless:set="test4">test4 failed: ${test4diff}</fail> </target> </project> \ No newline at end of file Modified: plugins/Beauty/trunk/build.xml =================================================================== --- plugins/Beauty/trunk/build.xml 2022-10-11 22:08:29 UTC (rev 25613) +++ plugins/Beauty/trunk/build.xml 2022-10-28 21:38:54 UTC (rev 25614) @@ -1,4 +1,4 @@ -<project name="Beauty" default="dist" basedir="."> +<project name="Beauty" default="dist" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless"> <echo>${java.home}</echo> <!-- read build.props to override properties set below --> @@ -74,14 +74,51 @@ <target name="compile" description="Compile" depends="init,setClasspath"> + + <!-- this is to use google's ErrorProne compiler plugin, which turns out + to be less useful than PMD. + <path id="processorpath.ref"> + <pathelement location="${user.home}/apps/apache-ant-1.10.12/lib/error_prone_core-2.16-with-dependencies.jar"/> + <pathelement location="${user.home}/apps/apache-ant-1.10.12/lib/dataflow-errorprone-3.15.0.jar"/> + </path> + <javac deprecation="on" debug="on" nowarn="on" + fork="yes" destdir="${classes.dir}" srcdir="${src.dir}" - includeantruntime="false" + includeantruntime="no" target="${target.version}" source="${target.version}"> + <classpath refid="classpathref" /> + <compilerarg value="-XDcompilePolicy=simple"/> + <compilerarg value="-processorpath"/> + <compilerarg pathref="processorpath.ref"/> + <compilerarg value="-Xplugin:ErrorProne -Xep:DeadException:ERROR" /> + should be dashJdashdashadd but of course dashdash isn't allowed in comments, because WTF, that would make sense + <compilerarg value="-J- -add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" /> + <compilerarg value="-J- -add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED" /> + <compilerarg value="-J- -add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED" /> + <compilerarg value="-J- -add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED" /> + <compilerarg value="-J- -add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED" /> + <compilerarg value="-J- -add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED" /> + <compilerarg value="-J- -add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED" /> + <compilerarg value="-J- -add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" /> + <compilerarg value="-J- -add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED" /> + <compilerarg value="-J- -add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED" /> + </javac> + --> + + <javac deprecation="on" + debug="on" + nowarn="on" + fork="yes" + destdir="${classes.dir}" + srcdir="${src.dir}" + includeantruntime="no" + target="${target.version}" + source="${target.version}"> <classpath refid="classpathref" /> </javac> <copy todir="${classes.dir}/docs" overwrite="no"> @@ -130,7 +167,7 @@ ========================================================================= --> <target name="dist" description="Compiles, jars, puts the jar in the jEdit jars directory." - depends="init,compile,prep_files"> + depends="clean,init,compile,prep_files,test"> <!-- make the plugin jar file --> @@ -258,7 +295,7 @@ - + <!-- this is for testing --> <target name="run" description="Run the application." depends="setClasspath"> @@ -274,9 +311,12 @@ <target name="all" depends="javacc,dist"/> <target name="test"> - <!-- - <ant antfile="ant_java_test.xml" /> - --> - <ant antfile="ant_json_test.xml" /> + <property environment="env" /> + <available file="diff" + filepath="${env.PATH}" + property="diff.present"/> + <ant if:true="${diff.present}" antfile="ant_java_test.xml" /> + <ant if:true="${diff.present}" antfile="ant_json_test.xml" /> + <echo unless:true="${diff.present}">Diff not available, no tests run.</echo> </target> </project> Modified: plugins/Beauty/trunk/src/beauty/options/BeautifierOptionPane.java =================================================================== --- plugins/Beauty/trunk/src/beauty/options/BeautifierOptionPane.java 2022-10-11 22:08:29 UTC (rev 25613) +++ plugins/Beauty/trunk/src/beauty/options/BeautifierOptionPane.java 2022-10-28 21:38:54 UTC (rev 25614) @@ -233,7 +233,7 @@ } // Entry class - class Entry implements Comparable { + class Entry implements Comparable<Entry> { String mode; String beautifier = null; @@ -254,7 +254,7 @@ } - public int compareTo( Object a ) { + public int compareTo( Entry a ) { return this.mode.compareToIgnoreCase( ( ( Entry ) a ).mode ); } } Modified: plugins/Beauty/trunk/src/beauty/parsers/bsh/JavaCharStream.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/bsh/JavaCharStream.java 2022-10-11 22:08:29 UTC (rev 25613) +++ plugins/Beauty/trunk/src/beauty/parsers/bsh/JavaCharStream.java 2022-10-28 21:38:54 UTC (rev 25614) @@ -464,7 +464,7 @@ public JavaCharStream(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { - this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); + this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); } /** Constructor. */ Modified: plugins/Beauty/trunk/src/beauty/parsers/java/JavaCharStream.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/JavaCharStream.java 2022-10-11 22:08:29 UTC (rev 25613) +++ plugins/Beauty/trunk/src/beauty/parsers/java/JavaCharStream.java 2022-10-28 21:38:54 UTC (rev 25614) @@ -444,7 +444,7 @@ public JavaCharStream(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { - this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); + this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); } public JavaCharStream(java.io.InputStream dstream, String encoding, int startline, Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaLexer.g4 =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaLexer.g4 2022-10-11 22:08:29 UTC (rev 25613) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaLexer.g4 2022-10-28 21:38:54 UTC (rev 25614) @@ -1,3 +1,4 @@ + /* [The "BSD licence"] Copyright (c) 2013 Terence Parr, Sam Harwell Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-10-11 22:08:29 UTC (rev 25613) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-10-28 21:38:54 UTC (rev 25614) @@ -964,7 +964,7 @@ output.append(packageDeclaration); output.append(importDeclarations); output.append(typeDeclarations); - + trim(output); } // all done! } @@ -4699,6 +4699,20 @@ } /** + * StringBuilder doesn't have a "trim" method. This trims whitespace from + * both ends of the string builder. There are two ways to use this, pass in a StringBuilder then use the same + * StringBuilder, it's start will have been trimmed, or pass in a StringBuilder + * and use the returned String. + * @param sb The StringBuilder to trim. + * @return The trimmed string. + */ + public String trim(StringBuilder sb) { + trimFront(sb); + trimEnd(sb); + return sb.toString(); + } + + /** * Pops the first item off the top of the stack. */ public String pop() { @@ -4786,43 +4800,32 @@ private void processComments(TerminalNode node) { Token token = node.getSymbol(); int tokenIndex = token.getTokenIndex(); - + // ... // End of Line Comments // ... // check to the right of the current token for an end of line comment, - // this handles both // and /* end of line comments. Only end of line + // this handles both // and /* */ end of line comments. Only end of line // comments are handled in this section, and such comments are appended - // to the end of the previous stack item. All other comments are handled + // to the end of the top stack item. All other comments are handled // by looking to the left of the current token and are prepended to the - // previous stack item. + // top stack item. List<Token> commentTokens = tokens.getHiddenTokensToRight(tokenIndex, 2); if (commentTokens != null && commentTokens.size() > 0 && token.getType() != Token.EOF) { // get the very next comment Token nextCommentToken = commentTokens.get(0); - - int commentIndex = nextCommentToken.getTokenIndex(); - - // get the hidden tokens between the current token and the next non-hidden token - List<Token> hiddenTokens = tokens.getHiddenTokensToRight(tokenIndex); - - // check if there is a line ender between the current token and the comment token - // is it "token \n comment" or "token comment \n"? - boolean hasLineEnder = false; - if (hiddenTokens != null && hiddenTokens.size() > 0) { - for (int i = 0; i < commentIndex - tokenIndex; i++) { - Token t = hiddenTokens.get(i); - String tokenText = t.getText(); - if (t.getChannel() == 1 && //JavaLexer.WS && - (tokenText.indexOf('\n') > -1 || tokenText.indexOf('\r') > -1)) { - hasLineEnder = true; - break; - } - } - if (!hasLineEnder) { - // have 'token comment' now check for line ender after the comment - hasLineEnder = false; - for (int i = commentIndex - tokenIndex; i < hiddenTokens.size(); i++) { + String nextCommentTokenText = nextCommentToken.getText(); + if (nextCommentToken.getType() == JavaLexer.LINE_COMMENT || (nextCommentToken.getType() == JavaLexer.COMMENT && nextCommentTokenText.lines().count() == 1)) { + int commentIndex = nextCommentToken.getTokenIndex(); + + // get the hidden tokens between the current token and the next non-hidden token + List<Token> hiddenTokens = tokens.getHiddenTokensToRight(tokenIndex); + + // check if there is a line ender between the current token and the comment token + // is it "token \n // comment" or "token // comment \n"? + boolean hasLineEnder = false; + if (hiddenTokens != null && hiddenTokens.size() > 0) { + for (int i = 0; i < commentIndex - tokenIndex; i++) { Token t = hiddenTokens.get(i); String tokenText = t.getText(); if (t.getChannel() == 1 && //JavaLexer.WS && @@ -4831,17 +4834,31 @@ break; } } - if (hasLineEnder) { - // have "token comment \n", append this comment to the end - // of the token. - StringBuilder item = new StringBuilder(pop()); - String comment = nextCommentToken.getText(); - if (item.indexOf(comment) == -1) { - item.append(tab).append(comment); - push(item); - tokens.seek(commentIndex + 1); - return; + if (!hasLineEnder) { + // have 'token comment' now check for line ender after the comment + hasLineEnder = false; + for (int i = commentIndex - tokenIndex; i < hiddenTokens.size(); i++) { + Token t = hiddenTokens.get(i); + String tokenText = t.getText(); + if (t.getChannel() == 1 && //JavaLexer.WS && + (tokenText.indexOf('\n') > -1 || tokenText... [truncated message content] |
From: <dal...@us...> - 2022-10-11 22:08:32
|
Revision: 25613 http://sourceforge.net/p/jedit/svn/25613 Author: daleanson Date: 2022-10-11 22:08:29 +0000 (Tue, 11 Oct 2022) Log Message: ----------- More updates on java 17 parser, fixes for comment handling. Modified Paths: -------------- plugins/Beauty/trunk/build.xml plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java plugins/Beauty/trunk/src/beauty/beautifiers/Java8Beautifier.java plugins/Beauty/trunk/src/beauty/beautifiers/JavaBeautifier.java plugins/Beauty/trunk/src/beauty/options/java/Java8OptionPane.java plugins/Beauty/trunk/src/beauty/options/java/JavaOptionPane.java plugins/Beauty/trunk/src/beauty/parsers/java/Java1.5.jj plugins/Beauty/trunk/src/beauty/parsers/java/antlr/ErrorListener.java plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8.g4 plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8BaseListener.java plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8BeautyListener.java plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8Lexer.java plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8Listener.java plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8Parser.java plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java plugins/Beauty/trunk/src/docs/index.html Modified: plugins/Beauty/trunk/build.xml =================================================================== --- plugins/Beauty/trunk/build.xml 2022-10-11 22:06:28 UTC (rev 25612) +++ plugins/Beauty/trunk/build.xml 2022-10-11 22:08:29 UTC (rev 25613) @@ -274,6 +274,9 @@ <target name="all" depends="javacc,dist"/> <target name="test"> + <!-- <ant antfile="ant_java_test.xml" /> + --> + <ant antfile="ant_json_test.xml" /> </target> </project> Modified: plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java =================================================================== --- plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java 2022-10-11 22:06:28 UTC (rev 25612) +++ plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java 2022-10-11 22:08:29 UTC (rev 25613) @@ -1,6 +1,7 @@ package beauty.beautifiers; +import beauty.parsers.ErrorListener; import beauty.parsers.ParserException; import beauty.parsers.java.java.*; Modified: plugins/Beauty/trunk/src/beauty/beautifiers/Java8Beautifier.java =================================================================== --- plugins/Beauty/trunk/src/beauty/beautifiers/Java8Beautifier.java 2022-10-11 22:06:28 UTC (rev 25612) +++ plugins/Beauty/trunk/src/beauty/beautifiers/Java8Beautifier.java 2022-10-11 22:08:29 UTC (rev 25613) @@ -16,7 +16,7 @@ import org.antlr.v4.runtime.tree.*; import org.gjt.sp.jedit.jEdit; - +// This is a newer parser based on Antlr and supports java 8 language. public class Java8Beautifier extends Beautifier { private int bracketStyle = 1; // JavaParser.ATTACHED; @@ -63,7 +63,7 @@ // set up the parser StringReader input = new StringReader( text ); - ANTLRInputStream antlrInput = new ANTLRInputStream( input ); + CharStream antlrInput = CharStreams.fromReader(input); Java8Lexer lexer = new Java8Lexer( antlrInput ); CommonTokenStream tokens = new CommonTokenStream( lexer ); Java8Parser javaParser = new Java8Parser( tokens ); @@ -100,7 +100,7 @@ // first try the faster SSL(*) parsing strategy javaParser.getInterpreter().setPredictionMode( PredictionMode.SLL ); - javaParser.getInterpreter().tail_call_preserves_sll = false; + //javaParser.getInterpreter().tail_call_preserves_sll = false; javaParser.removeErrorListeners(); javaParser.setErrorHandler( new BailErrorStrategy() ); tree = javaParser.compilationUnit(); @@ -111,7 +111,9 @@ // if first parse fails, try again with slower LL(*) parse // Actually, the slowness happens in the first parse, since the // input was tokenized there and is reused here. - tokens.reset(); // rewind input stream + // deprecated: + //tokens.reset(); // rewind input stream + tokens.seek(0); // rewind input stream javaParser.reset(); // add an error listener to the parser to capture any real errors @@ -119,8 +121,8 @@ errorListener = new ErrorListener(); javaParser.addErrorListener( errorListener ); javaParser.setErrorHandler( new DefaultErrorStrategy() ); - javaParser.getInterpreter().tail_call_preserves_sll = false; - javaParser.getInterpreter().enable_global_context_dfa = true; + //javaParser.getInterpreter().tail_call_preserves_sll = false; + //javaParser.getInterpreter().enable_global_context_dfa = true; // reparse with full LL(*) javaParser.getInterpreter().setPredictionMode( PredictionMode.LL ); Modified: plugins/Beauty/trunk/src/beauty/beautifiers/JavaBeautifier.java =================================================================== --- plugins/Beauty/trunk/src/beauty/beautifiers/JavaBeautifier.java 2022-10-11 22:06:28 UTC (rev 25612) +++ plugins/Beauty/trunk/src/beauty/beautifiers/JavaBeautifier.java 2022-10-11 22:08:29 UTC (rev 25613) @@ -8,6 +8,7 @@ import org.gjt.sp.jedit.jEdit; +// This is the old parser for java 7 and below, it uses the javacc parser. public class JavaBeautifier extends Beautifier { private static JavaParser parser = null; Modified: plugins/Beauty/trunk/src/beauty/options/java/Java8OptionPane.java =================================================================== --- plugins/Beauty/trunk/src/beauty/options/java/Java8OptionPane.java 2022-10-11 22:06:28 UTC (rev 25612) +++ plugins/Beauty/trunk/src/beauty/options/java/Java8OptionPane.java 2022-10-11 22:08:29 UTC (rev 25613) @@ -17,7 +17,6 @@ private JCheckBox sortImports; private JCheckBox groupImports; private NumberTextField blankLinesBetweenImportGroups; - private NumberTextField blankLinesAfterClassDeclaration; private NumberTextField blankLinesAfterClassBody; private NumberTextField blankLinesBeforeMethods; private NumberTextField blankLinesAfterMethods; @@ -54,10 +53,6 @@ blankLinesBetweenImportGroups = new NumberTextField( 0, 100 ); blankLinesBetweenImportGroups.setValue( jEdit.getIntegerProperty( "beauty.java8.blankLinesBetweenImportGroups", 1 ) ); - JLabel blankLinesAfterClassDeclarationLabel = new JLabel( jEdit.getProperty( "beauty.java8.Blank_Lines_After_Class_Declaration", "Blank Lines After Class Declaration" ) ); - blankLinesAfterClassDeclaration = new NumberTextField( 0, 100 ); - blankLinesAfterClassDeclaration.setValue( jEdit.getIntegerProperty( "beauty.java8.blankLinesAfterClassDeclaration", 1 ) ); - JLabel blankLinesAfterClassBodyLabel = new JLabel( jEdit.getProperty( "beauty.java8.Blank_Lines_After_Class_Body", "Blank Lines After Class Body" ) ); blankLinesAfterClassBody = new NumberTextField( 0, 100 ); blankLinesAfterClassBody.setValue( jEdit.getIntegerProperty( "beauty.java8.blankLinesAfterClassBody", 1 ) ); @@ -92,19 +87,17 @@ add( "0, 5, 1, 1, W, w, 3", groupImports ); add( "0, 6, 1, 1, W, w, 3", blankLinesBetweenImportGroupsLabel ); add( "1, 6, 1, 1, W, w, 3", blankLinesBetweenImportGroups ); - add( "0, 7, 1, 1, W, w, 3", blankLinesAfterClassDeclarationLabel ); - add( "1, 7, 1, 1, W, w, 3", blankLinesAfterClassDeclaration ); - add( "0, 8, 1, 1, W, w, 3", blankLinesAfterClassBodyLabel ); - add( "1, 8, 1, 1, W, w, 3", blankLinesAfterClassBody ); - add( "0, 9, 1, 1, W, w, 3", blankLinesBeforeMethodsLabel ); - add( "1, 9, 1, 1, W, w, 3", blankLinesBeforeMethods ); - add( "0, 10,1, 1, W, w, 3", blankLinesAfterMethodsLabel ); - add( "1, 10,1, 1, W, w, 3", blankLinesAfterMethods ); - add( "0, 11,1, 1, W, w, 3", sortModifiers ); - add( "0, 12,1, 1, W, w, 3", collapseMultipleBlankLinesToLabel ); - add( "1, 12,1, 1, W, w, 3", collapseMultipleBlankLinesTo ); - add( "0, 13,1, 1, W, w, 3", wrapLongLinesLengthLabel ); - add( "1, 13,1, 1, W, w, 3", wrapLongLinesLength ); + add( "0, 7, 1, 1, W, w, 3", blankLinesAfterClassBodyLabel ); + add( "1, 7, 1, 1, W, w, 3", blankLinesAfterClassBody ); + add( "0, 8, 1, 1, W, w, 3", blankLinesBeforeMethodsLabel ); + add( "1, 8, 1, 1, W, w, 3", blankLinesBeforeMethods ); + add( "0, 9 ,1, 1, W, w, 3", blankLinesAfterMethodsLabel ); + add( "1, 9 ,1, 1, W, w, 3", blankLinesAfterMethods ); + add( "0, 10,1, 1, W, w, 3", sortModifiers ); + add( "0, 11,1, 1, W, w, 3", collapseMultipleBlankLinesToLabel ); + add( "1, 11,1, 1, W, w, 3", collapseMultipleBlankLinesTo ); + add( "0, 12,1, 1, W, w, 3", wrapLongLinesLengthLabel ); + add( "1, 12,1, 1, W, w, 3", wrapLongLinesLength ); } public void _save() { @@ -114,7 +107,6 @@ jEdit.setBooleanProperty( "beauty.java8.sortImports", sortImports.isSelected() ); jEdit.setBooleanProperty( "beauty.java8.groupImports", groupImports.isSelected() ); jEdit.setIntegerProperty( "beauty.java8.blankLinesBetweenImportGroups", blankLinesBetweenImportGroups.getValue() ); - jEdit.setIntegerProperty( "beauty.java8.blankLinesAfterClassDeclaration", blankLinesAfterClassDeclaration.getValue() ); jEdit.setIntegerProperty( "beauty.java8.blankLinesAfterClassBody", blankLinesAfterClassBody.getValue() ); jEdit.setIntegerProperty( "beauty.java8.blankLinesBeforeMethods", blankLinesBeforeMethods.getValue() ); jEdit.setIntegerProperty( "beauty.java8.blankLinesAfterMethods", blankLinesAfterMethods.getValue() ); Modified: plugins/Beauty/trunk/src/beauty/options/java/JavaOptionPane.java =================================================================== --- plugins/Beauty/trunk/src/beauty/options/java/JavaOptionPane.java 2022-10-11 22:06:28 UTC (rev 25612) +++ plugins/Beauty/trunk/src/beauty/options/java/JavaOptionPane.java 2022-10-11 22:08:29 UTC (rev 25613) @@ -1,7 +1,7 @@ package beauty.options.java; -import beauty.parsers.java.JavaParser; +import beauty.parsers.java.java.JavaParserBeautyListener; import ise.java.awt.*; @@ -32,7 +32,7 @@ public JavaOptionPane() { super(); - bracketStyle = jEdit.getIntegerProperty( "beauty.java.bracketStyle", JavaParser.ATTACHED ); + bracketStyle = jEdit.getIntegerProperty( "beauty.java.bracketStyle", JavaParserBeautyListener.ATTACHED ); } // called when this class is first accessed @@ -55,14 +55,14 @@ bg.add( brokenBrackets ); breakElse = new JCheckBox( "<html>" + jEdit.getProperty( "beauty.msg.Break", "Break" ) + " 'else', 'catch', 'while', e.g.<br>}<br>else" ); breakElse.setSelected( jEdit.getBooleanProperty( "beauty.java.breakElse", false ) ); - breakElse.setEnabled( bracketStyle == JavaParser.ATTACHED ); + breakElse.setEnabled( bracketStyle == JavaParserBeautyListener.ATTACHED ); switch ( bracketStyle ) { - case JavaParser.ATTACHED: + case JavaParserBeautyListener.ATTACHED: attachedBrackets.setSelected( true ); brokenBrackets.setSelected( false ); break; - case JavaParser.BROKEN: + case JavaParserBeautyListener.BROKEN: attachedBrackets.setSelected( false ); brokenBrackets.setSelected( true ); breakElse.setSelected( true ); @@ -80,15 +80,15 @@ public void actionPerformed( ActionEvent ae ) { if ( attachedBrackets.equals( ae.getSource() ) ) { - bracketStyle = JavaParser.ATTACHED; + bracketStyle = JavaParserBeautyListener.ATTACHED; } else if ( brokenBrackets.equals( ae.getSource() ) ) { - bracketStyle = JavaParser.BROKEN; + bracketStyle = JavaParserBeautyListener.BROKEN; breakElse.setSelected( true ); } - breakElse.setEnabled( bracketStyle == JavaParser.ATTACHED ); + breakElse.setEnabled( bracketStyle == JavaParserBeautyListener.ATTACHED ); } }; attachedBrackets.addActionListener( al ); Modified: plugins/Beauty/trunk/src/beauty/parsers/java/Java1.5.jj =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/Java1.5.jj 2022-10-11 22:06:28 UTC (rev 25612) +++ plugins/Beauty/trunk/src/beauty/parsers/java/Java1.5.jj 2022-10-11 22:08:29 UTC (rev 25613) @@ -1,4 +1,10 @@ +/* Well now, it's 2022 and this code hasn't been maintained in forever. +It's been bypassed by a better parser generator, see the newer code. + +Read and weep! + +*/ /* Per Sreenivasa Viswanadha (as posted on the javacc user mailing list), the original java 1.5 grammar is licensed under the BSD license, so this modified Modified: plugins/Beauty/trunk/src/beauty/parsers/java/antlr/ErrorListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/antlr/ErrorListener.java 2022-10-11 22:06:28 UTC (rev 25612) +++ plugins/Beauty/trunk/src/beauty/parsers/java/antlr/ErrorListener.java 2022-10-11 22:08:29 UTC (rev 25613) @@ -6,8 +6,6 @@ import java.util.*; import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.misc.NotNull; -import org.antlr.v4.runtime.misc.Nullable; public class ErrorListener extends BaseErrorListener { @@ -17,8 +15,7 @@ return errors; } - @Override - public <T extends Token> void syntaxError( @NotNull Recognizer<T, ?> recognizer, @Nullable T offendingSymbol, int line, int charPositionInLine, @NotNull String msg, @Nullable RecognitionException e ) { + public <T extends Token> void syntaxError( Recognizer<T, ?> recognizer, T offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e ) { int length = 0; if ( e != null && e.getOffendingToken() != null ) { int startOffset = e.getOffendingToken().getStartIndex(); Modified: plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8.g4 =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8.g4 2022-10-11 22:06:28 UTC (rev 25612) +++ plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8.g4 2022-10-11 22:08:29 UTC (rev 25613) @@ -1834,22 +1834,22 @@ // Whitespace and comments // -WS : [ \t\r\n\u000C]+ -> channel(WHITESPACE) +WS : [ \t\r\n\u000C]+ -> channel(1) // was WHITESPACE ; DOC_COMMENT - : '/**' .*? '*/' -> channel(COMMENTS) + : '/**' .*? '*/' -> channel(2) // was COMMENT ; COMMENT - : '/*' .*? '*/' -> channel(COMMENTS) + : '/*' .*? '*/' -> channel(2) // was COMMENT ; JEDIT_FOLD_MARKER - : '//' [ ]* '}}}' -> channel(COMMENTS) + : '//' [ ]* '}}}' -> channel(2) // was COMMENT ; LINE_COMMENT - : '//' ~[\r\n]* -> channel(COMMENTS) + : '//' ~[\r\n]* -> channel(2) // was COMMENT ; Modified: plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8BaseListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8BaseListener.java 2022-10-11 22:06:28 UTC (rev 25612) +++ plugins/Beauty/trunk/src/beauty/parsers/java/antlr/Java8BaseListener.java 2022-10-11 22:08:29 UTC (rev 25613) @@ -1,11 +1,9 @@ -// Generated from /home/danson/src/jedit/plugins/Beauty/src/beauty/parsers/java/antlr/Java8.g4 by ANTLR 4.x +// Generated from /home/danson/src/jedit/plugins/Beauty/src/beauty/parsers/java/antlr/Java8.g4 by ANTLR 4.10.1 package beauty.parsers.java.antlr; import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.tree.ErrorNode; import org.antlr.v4.runtime.tree.TerminalNode; @@ -20,2989 +18,2989 @@ * * <p>The default implementation does nothing.</p> */ - @Override public void enterLiteral(@NotNull Java8Parser.LiteralContext ctx) { } + @Override public void enterLiteral(Java8Parser.LiteralContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitLiteral(@NotNull Java8Parser.LiteralContext ctx) { } + @Override public void exitLiteral(Java8Parser.LiteralContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterType(@NotNull Java8Parser.TypeContext ctx) { } + @Override public void enterType(Java8Parser.TypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitType(@NotNull Java8Parser.TypeContext ctx) { } + @Override public void exitType(Java8Parser.TypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterPrimitiveType(@NotNull Java8Parser.PrimitiveTypeContext ctx) { } + @Override public void enterPrimitiveType(Java8Parser.PrimitiveTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitPrimitiveType(@NotNull Java8Parser.PrimitiveTypeContext ctx) { } + @Override public void exitPrimitiveType(Java8Parser.PrimitiveTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterNumericType(@NotNull Java8Parser.NumericTypeContext ctx) { } + @Override public void enterNumericType(Java8Parser.NumericTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitNumericType(@NotNull Java8Parser.NumericTypeContext ctx) { } + @Override public void exitNumericType(Java8Parser.NumericTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterIntegralType(@NotNull Java8Parser.IntegralTypeContext ctx) { } + @Override public void enterIntegralType(Java8Parser.IntegralTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitIntegralType(@NotNull Java8Parser.IntegralTypeContext ctx) { } + @Override public void exitIntegralType(Java8Parser.IntegralTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterFloatingPointType(@NotNull Java8Parser.FloatingPointTypeContext ctx) { } + @Override public void enterFloatingPointType(Java8Parser.FloatingPointTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitFloatingPointType(@NotNull Java8Parser.FloatingPointTypeContext ctx) { } + @Override public void exitFloatingPointType(Java8Parser.FloatingPointTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterReferenceType(@NotNull Java8Parser.ReferenceTypeContext ctx) { } + @Override public void enterReferenceType(Java8Parser.ReferenceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitReferenceType(@NotNull Java8Parser.ReferenceTypeContext ctx) { } + @Override public void exitReferenceType(Java8Parser.ReferenceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterClassOrInterfaceType(@NotNull Java8Parser.ClassOrInterfaceTypeContext ctx) { } + @Override public void enterClassOrInterfaceType(Java8Parser.ClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitClassOrInterfaceType(@NotNull Java8Parser.ClassOrInterfaceTypeContext ctx) { } + @Override public void exitClassOrInterfaceType(Java8Parser.ClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterClassType(@NotNull Java8Parser.ClassTypeContext ctx) { } + @Override public void enterClassType(Java8Parser.ClassTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitClassType(@NotNull Java8Parser.ClassTypeContext ctx) { } + @Override public void exitClassType(Java8Parser.ClassTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterClassType_lf_classOrInterfaceType(@NotNull Java8Parser.ClassType_lf_classOrInterfaceTypeContext ctx) { } + @Override public void enterClassType_lf_classOrInterfaceType(Java8Parser.ClassType_lf_classOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitClassType_lf_classOrInterfaceType(@NotNull Java8Parser.ClassType_lf_classOrInterfaceTypeContext ctx) { } + @Override public void exitClassType_lf_classOrInterfaceType(Java8Parser.ClassType_lf_classOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterClassType_lfno_classOrInterfaceType(@NotNull Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx) { } + @Override public void enterClassType_lfno_classOrInterfaceType(Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitClassType_lfno_classOrInterfaceType(@NotNull Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx) { } + @Override public void exitClassType_lfno_classOrInterfaceType(Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterInterfaceType(@NotNull Java8Parser.InterfaceTypeContext ctx) { } + @Override public void enterInterfaceType(Java8Parser.InterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitInterfaceType(@NotNull Java8Parser.InterfaceTypeContext ctx) { } + @Override public void exitInterfaceType(Java8Parser.InterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterInterfaceType_lf_classOrInterfaceType(@NotNull Java8Parser.InterfaceType_lf_classOrInterfaceTypeContext ctx) { } + @Override public void enterInterfaceType_lf_classOrInterfaceType(Java8Parser.InterfaceType_lf_classOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitInterfaceType_lf_classOrInterfaceType(@NotNull Java8Parser.InterfaceType_lf_classOrInterfaceTypeContext ctx) { } + @Override public void exitInterfaceType_lf_classOrInterfaceType(Java8Parser.InterfaceType_lf_classOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterInterfaceType_lfno_classOrInterfaceType(@NotNull Java8Parser.InterfaceType_lfno_classOrInterfaceTypeContext ctx) { } + @Override public void enterInterfaceType_lfno_classOrInterfaceType(Java8Parser.InterfaceType_lfno_classOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitInterfaceType_lfno_classOrInterfaceType(@NotNull Java8Parser.InterfaceType_lfno_classOrInterfaceTypeContext ctx) { } + @Override public void exitInterfaceType_lfno_classOrInterfaceType(Java8Parser.InterfaceType_lfno_classOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeVariable(@NotNull Java8Parser.TypeVariableContext ctx) { } + @Override public void enterTypeVariable(Java8Parser.TypeVariableContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeVariable(@NotNull Java8Parser.TypeVariableContext ctx) { } + @Override public void exitTypeVariable(Java8Parser.TypeVariableContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterArrayType(@NotNull Java8Parser.ArrayTypeContext ctx) { } + @Override public void enterArrayType(Java8Parser.ArrayTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitArrayType(@NotNull Java8Parser.ArrayTypeContext ctx) { } + @Override public void exitArrayType(Java8Parser.ArrayTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterDims(@NotNull Java8Parser.DimsContext ctx) { } + @Override public void enterDims(Java8Parser.DimsContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitDims(@NotNull Java8Parser.DimsContext ctx) { } + @Override public void exitDims(Java8Parser.DimsContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeParameter(@NotNull Java8Parser.TypeParameterContext ctx) { } + @Override public void enterTypeParameter(Java8Parser.TypeParameterContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeParameter(@NotNull Java8Parser.TypeParameterContext ctx) { } + @Override public void exitTypeParameter(Java8Parser.TypeParameterContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeParameterModifier(@NotNull Java8Parser.TypeParameterModifierContext ctx) { } + @Override public void enterTypeParameterModifier(Java8Parser.TypeParameterModifierContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeParameterModifier(@NotNull Java8Parser.TypeParameterModifierContext ctx) { } + @Override public void exitTypeParameterModifier(Java8Parser.TypeParameterModifierContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeBound(@NotNull Java8Parser.TypeBoundContext ctx) { } + @Override public void enterTypeBound(Java8Parser.TypeBoundContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeBound(@NotNull Java8Parser.TypeBoundContext ctx) { } + @Override public void exitTypeBound(Java8Parser.TypeBoundContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterAdditionalBound(@NotNull Java8Parser.AdditionalBoundContext ctx) { } + @Override public void enterAdditionalBound(Java8Parser.AdditionalBoundContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitAdditionalBound(@NotNull Java8Parser.AdditionalBoundContext ctx) { } + @Override public void exitAdditionalBound(Java8Parser.AdditionalBoundContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeArguments(@NotNull Java8Parser.TypeArgumentsContext ctx) { } + @Override public void enterTypeArguments(Java8Parser.TypeArgumentsContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeArguments(@NotNull Java8Parser.TypeArgumentsContext ctx) { } + @Override public void exitTypeArguments(Java8Parser.TypeArgumentsContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeArgumentList(@NotNull Java8Parser.TypeArgumentListContext ctx) { } + @Override public void enterTypeArgumentList(Java8Parser.TypeArgumentListContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeArgumentList(@NotNull Java8Parser.TypeArgumentListContext ctx) { } + @Override public void exitTypeArgumentList(Java8Parser.TypeArgumentListContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeArgument(@NotNull Java8Parser.TypeArgumentContext ctx) { } + @Override public void enterTypeArgument(Java8Parser.TypeArgumentContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeArgument(@NotNull Java8Parser.TypeArgumentContext ctx) { } + @Override public void exitTypeArgument(Java8Parser.TypeArgumentContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterWildcard(@NotNull Java8Parser.WildcardContext ctx) { } + @Override public void enterWildcard(Java8Parser.WildcardContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitWildcard(@NotNull Java8Parser.WildcardContext ctx) { } + @Override public void exitWildcard(Java8Parser.WildcardContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterWildcardBounds(@NotNull Java8Parser.WildcardBoundsContext ctx) { } + @Override public void enterWildcardBounds(Java8Parser.WildcardBoundsContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitWildcardBounds(@NotNull Java8Parser.WildcardBoundsContext ctx) { } + @Override public void exitWildcardBounds(Java8Parser.WildcardBoundsContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterPackageName(@NotNull Java8Parser.PackageNameContext ctx) { } + @Override public void enterPackageName(Java8Parser.PackageNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitPackageName(@NotNull Java8Parser.PackageNameContext ctx) { } + @Override public void exitPackageName(Java8Parser.PackageNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeName(@NotNull Java8Parser.TypeNameContext ctx) { } + @Override public void enterTypeName(Java8Parser.TypeNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeName(@NotNull Java8Parser.TypeNameContext ctx) { } + @Override public void exitTypeName(Java8Parser.TypeNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterPackageOrTypeName(@NotNull Java8Parser.PackageOrTypeNameContext ctx) { } + @Override public void enterPackageOrTypeName(Java8Parser.PackageOrTypeNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitPackageOrTypeName(@NotNull Java8Parser.PackageOrTypeNameContext ctx) { } + @Override public void exitPackageOrTypeName(Java8Parser.PackageOrTypeNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterExpressionName(@NotNull Java8Parser.ExpressionNameContext ctx) { } + @Override public void enterExpressionName(Java8Parser.ExpressionNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitExpressionName(@NotNull Java8Parser.ExpressionNameContext ctx) { } + @Override public void exitExpressionName(Java8Parser.ExpressionNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterMethodName(@NotNull Java8Parser.MethodNameContext ctx) { } + @Override public void enterMethodName(Java8Parser.MethodNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitMethodName(@NotNull Java8Parser.MethodNameContext ctx) { } + @Override public void exitMethodName(Java8Parser.MethodNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterAmbiguousName(@NotNull Java8Parser.AmbiguousNameContext ctx) { } + @Override public void enterAmbiguousName(Java8Parser.AmbiguousNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitAmbiguousName(@NotNull Java8Parser.AmbiguousNameContext ctx) { } + @Override public void exitAmbiguousName(Java8Parser.AmbiguousNameContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterCompilationUnit(@NotNull Java8Parser.CompilationUnitContext ctx) { } + @Override public void enterCompilationUnit(Java8Parser.CompilationUnitContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitCompilationUnit(@NotNull Java8Parser.CompilationUnitContext ctx) { } + @Override public void exitCompilationUnit(Java8Parser.CompilationUnitContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterPackageDeclaration(@NotNull Java8Parser.PackageDeclarationContext ctx) { } + @Override public void enterPackageDeclaration(Java8Parser.PackageDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitPackageDeclaration(@NotNull Java8Parser.PackageDeclarationContext ctx) { } + @Override public void exitPackageDeclaration(Java8Parser.PackageDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterPackageModifier(@NotNull Java8Parser.PackageModifierContext ctx) { } + @Override public void enterPackageModifier(Java8Parser.PackageModifierContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitPackageModifier(@NotNull Java8Parser.PackageModifierContext ctx) { } + @Override public void exitPackageModifier(Java8Parser.PackageModifierContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterImportDeclaration(@NotNull Java8Parser.ImportDeclarationContext ctx) { } + @Override public void enterImportDeclaration(Java8Parser.ImportDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitImportDeclaration(@NotNull Java8Parser.ImportDeclarationContext ctx) { } + @Override public void exitImportDeclaration(Java8Parser.ImportDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterSingleTypeImportDeclaration(@NotNull Java8Parser.SingleTypeImportDeclarationContext ctx) { } + @Override public void enterSingleTypeImportDeclaration(Java8Parser.SingleTypeImportDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitSingleTypeImportDeclaration(@NotNull Java8Parser.SingleTypeImportDeclarationContext ctx) { } + @Override public void exitSingleTypeImportDeclaration(Java8Parser.SingleTypeImportDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeImportOnDemandDeclaration(@NotNull Java8Parser.TypeImportOnDemandDeclarationContext ctx) { } + @Override public void enterTypeImportOnDemandDeclaration(Java8Parser.TypeImportOnDemandDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeImportOnDemandDeclaration(@NotNull Java8Parser.TypeImportOnDemandDeclarationContext ctx) { } + @Override public void exitTypeImportOnDemandDeclaration(Java8Parser.TypeImportOnDemandDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterSingleStaticImportDeclaration(@NotNull Java8Parser.SingleStaticImportDeclarationContext ctx) { } + @Override public void enterSingleStaticImportDeclaration(Java8Parser.SingleStaticImportDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitSingleStaticImportDeclaration(@NotNull Java8Parser.SingleStaticImportDeclarationContext ctx) { } + @Override public void exitSingleStaticImportDeclaration(Java8Parser.SingleStaticImportDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterStaticImportOnDemandDeclaration(@NotNull Java8Parser.StaticImportOnDemandDeclarationContext ctx) { } + @Override public void enterStaticImportOnDemandDeclaration(Java8Parser.StaticImportOnDemandDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitStaticImportOnDemandDeclaration(@NotNull Java8Parser.StaticImportOnDemandDeclarationContext ctx) { } + @Override public void exitStaticImportOnDemandDeclaration(Java8Parser.StaticImportOnDemandDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeDeclaration(@NotNull Java8Parser.TypeDeclarationContext ctx) { } + @Override public void enterTypeDeclaration(Java8Parser.TypeDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeDeclaration(@NotNull Java8Parser.TypeDeclarationContext ctx) { } + @Override public void exitTypeDeclaration(Java8Parser.TypeDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterClassDeclaration(@NotNull Java8Parser.ClassDeclarationContext ctx) { } + @Override public void enterClassDeclaration(Java8Parser.ClassDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitClassDeclaration(@NotNull Java8Parser.ClassDeclarationContext ctx) { } + @Override public void exitClassDeclaration(Java8Parser.ClassDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterNormalClassDeclaration(@NotNull Java8Parser.NormalClassDeclarationContext ctx) { } + @Override public void enterNormalClassDeclaration(Java8Parser.NormalClassDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitNormalClassDeclaration(@NotNull Java8Parser.NormalClassDeclarationContext ctx) { } + @Override public void exitNormalClassDeclaration(Java8Parser.NormalClassDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterClassModifiers(@NotNull Java8Parser.ClassModifiersContext ctx) { } + @Override public void enterClassModifiers(Java8Parser.ClassModifiersContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitClassModifiers(@NotNull Java8Parser.ClassModifiersContext ctx) { } + @Override public void exitClassModifiers(Java8Parser.ClassModifiersContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterClassModifier(@NotNull Java8Parser.ClassModifierContext ctx) { } + @Override public void enterClassModifier(Java8Parser.ClassModifierContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitClassModifier(@NotNull Java8Parser.ClassModifierContext ctx) { } + @Override public void exitClassModifier(Java8Parser.ClassModifierContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeParameters(@NotNull Java8Parser.TypeParametersContext ctx) { } + @Override public void enterTypeParameters(Java8Parser.TypeParametersContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeParameters(@NotNull Java8Parser.TypeParametersContext ctx) { } + @Override public void exitTypeParameters(Java8Parser.TypeParametersContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterTypeParameterList(@NotNull Java8Parser.TypeParameterListContext ctx) { } + @Override public void enterTypeParameterList(Java8Parser.TypeParameterListContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitTypeParameterList(@NotNull Java8Parser.TypeParameterListContext ctx) { } + @Override public void exitTypeParameterList(Java8Parser.TypeParameterListContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterSuperclass(@NotNull Java8Parser.SuperclassContext ctx) { } + @Override public void enterSuperclass(Java8Parser.SuperclassContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitSuperclass(@NotNull Java8Parser.SuperclassContext ctx) { } + @Override public void exitSuperclass(Java8Parser.SuperclassContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterSuperinterfaces(@NotNull Java8Parser.SuperinterfacesContext ctx) { } + @Override public void enterSuperinterfaces(Java8Parser.SuperinterfacesContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitSuperinterfaces(@NotNull Java8Parser.SuperinterfacesContext ctx) { } + @Override public void exitSuperinterfaces(Java8Parser.SuperinterfacesContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterInterfaceTypeList(@NotNull Java8Parser.InterfaceTypeListContext ctx) { } + @Override public void enterInterfaceTypeList(Java8Parser.InterfaceTypeListContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitInterfaceTypeList(@NotNull Java8Parser.InterfaceTypeListContext ctx) { } + @Override public void exitInterfaceTypeList(Java8Parser.InterfaceTypeListContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterClassBody(@NotNull Java8Parser.ClassBodyContext ctx) { } + @Override public void enterClassBody(Java8Parser.ClassBodyContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitClassBody(@NotNull Java8Parser.ClassBodyContext ctx) { } + @Override public void exitClassBody(Java8Parser.ClassBodyContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterClassBodyDeclaration(@NotNull Java8Parser.ClassBodyDeclarationContext ctx) { } + @Override public void enterClassBodyDeclaration(Java8Parser.ClassBodyDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitClassBodyDeclaration(@NotNull Java8Parser.ClassBodyDeclarationContext ctx) { } + @Override public void exitClassBodyDeclaration(Java8Parser.ClassBodyDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterClassMemberDeclaration(@NotNull Java8Parser.ClassMemberDeclarationContext ctx) { } + @Override public void enterClassMemberDeclaration(Java8Parser.ClassMemberDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitClassMemberDeclaration(@NotNull Java8Parser.ClassMemberDeclarationContext ctx) { } + @Override public void exitClassMemberDeclaration(Java8Parser.ClassMemberDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterFieldDeclaration(@NotNull Java8Parser.FieldDeclarationContext ctx) { } + @Override public void enterFieldDeclaration(Java8Parser.FieldDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitFieldDeclaration(@NotNull Java8Parser.FieldDeclarationContext ctx) { } + @Override public void exitFieldDeclaration(Java8Parser.FieldDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterFieldModifiers(@NotNull Java8Parser.FieldModifiersContext ctx) { } + @Override public void enterFieldModifiers(Java8Parser.FieldModifiersContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitFieldModifiers(@NotNull Java8Parser.FieldModifiersContext ctx) { } + @Override public void exitFieldModifiers(Java8Parser.FieldModifiersContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterFieldModifier(@NotNull Java8Parser.FieldModifierContext ctx) { } + @Override public void enterFieldModifier(Java8Parser.FieldModifierContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitFieldModifier(@NotNull Java8Parser.FieldModifierContext ctx) { } + @Override public void exitFieldModifier(Java8Parser.FieldModifierContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterVariableDeclaratorList(@NotNull Java8Parser.VariableDeclaratorListContext ctx) { } + @Override public void enterVariableDeclaratorList(Java8Parser.VariableDeclaratorListContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitVariableDeclaratorList(@NotNull Java8Parser.VariableDeclaratorListContext ctx) { } + @Override public void exitVariableDeclaratorList(Java8Parser.VariableDeclaratorListContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterVariableDeclarator(@NotNull Java8Parser.VariableDeclaratorContext ctx) { } + @Override public void enterVariableDeclarator(Java8Parser.VariableDeclaratorContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitVariableDeclarator(@NotNull Java8Parser.VariableDeclaratorContext ctx) { } + @Override public void exitVariableDeclarator(Java8Parser.VariableDeclaratorContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterVariableDeclaratorId(@NotNull Java8Parser.VariableDeclaratorIdContext ctx) { } + @Override public void enterVariableDeclaratorId(Java8Parser.VariableDeclaratorIdContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitVariableDeclaratorId(@NotNull Java8Parser.VariableDeclaratorIdContext ctx) { } + @Override public void exitVariableDeclaratorId(Java8Parser.VariableDeclaratorIdContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterVariableInitializer(@NotNull Java8Parser.VariableInitializerContext ctx) { } + @Override public void enterVariableInitializer(Java8Parser.VariableInitializerContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitVariableInitializer(@NotNull Java8Parser.VariableInitializerContext ctx) { } + @Override public void exitVariableInitializer(Java8Parser.VariableInitializerContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannType(@NotNull Java8Parser.UnannTypeContext ctx) { } + @Override public void enterUnannType(Java8Parser.UnannTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannType(@NotNull Java8Parser.UnannTypeContext ctx) { } + @Override public void exitUnannType(Java8Parser.UnannTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannPrimitiveType(@NotNull Java8Parser.UnannPrimitiveTypeContext ctx) { } + @Override public void enterUnannPrimitiveType(Java8Parser.UnannPrimitiveTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannPrimitiveType(@NotNull Java8Parser.UnannPrimitiveTypeContext ctx) { } + @Override public void exitUnannPrimitiveType(Java8Parser.UnannPrimitiveTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannReferenceType(@NotNull Java8Parser.UnannReferenceTypeContext ctx) { } + @Override public void enterUnannReferenceType(Java8Parser.UnannReferenceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannReferenceType(@NotNull Java8Parser.UnannReferenceTypeContext ctx) { } + @Override public void exitUnannReferenceType(Java8Parser.UnannReferenceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannClassOrInterfaceType(@NotNull Java8Parser.UnannClassOrInterfaceTypeContext ctx) { } + @Override public void enterUnannClassOrInterfaceType(Java8Parser.UnannClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannClassOrInterfaceType(@NotNull Java8Parser.UnannClassOrInterfaceTypeContext ctx) { } + @Override public void exitUnannClassOrInterfaceType(Java8Parser.UnannClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannClassType(@NotNull Java8Parser.UnannClassTypeContext ctx) { } + @Override public void enterUnannClassType(Java8Parser.UnannClassTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannClassType(@NotNull Java8Parser.UnannClassTypeContext ctx) { } + @Override public void exitUnannClassType(Java8Parser.UnannClassTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannClassType_lf_unannClassOrInterfaceType(@NotNull Java8Parser.UnannClassType_lf_unannClassOrInterfaceTypeContext ctx) { } + @Override public void enterUnannClassType_lf_unannClassOrInterfaceType(Java8Parser.UnannClassType_lf_unannClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannClassType_lf_unannClassOrInterfaceType(@NotNull Java8Parser.UnannClassType_lf_unannClassOrInterfaceTypeContext ctx) { } + @Override public void exitUnannClassType_lf_unannClassOrInterfaceType(Java8Parser.UnannClassType_lf_unannClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannClassType_lfno_unannClassOrInterfaceType(@NotNull Java8Parser.UnannClassType_lfno_unannClassOrInterfaceTypeContext ctx) { } + @Override public void enterUnannClassType_lfno_unannClassOrInterfaceType(Java8Parser.UnannClassType_lfno_unannClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannClassType_lfno_unannClassOrInterfaceType(@NotNull Java8Parser.UnannClassType_lfno_unannClassOrInterfaceTypeContext ctx) { } + @Override public void exitUnannClassType_lfno_unannClassOrInterfaceType(Java8Parser.UnannClassType_lfno_unannClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannInterfaceType(@NotNull Java8Parser.UnannInterfaceTypeContext ctx) { } + @Override public void enterUnannInterfaceType(Java8Parser.UnannInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannInterfaceType(@NotNull Java8Parser.UnannInterfaceTypeContext ctx) { } + @Override public void exitUnannInterfaceType(Java8Parser.UnannInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannInterfaceType_lf_unannClassOrInterfaceType(@NotNull Java8Parser.UnannInterfaceType_lf_unannClassOrInterfaceTypeContext ctx) { } + @Override public void enterUnannInterfaceType_lf_unannClassOrInterfaceType(Java8Parser.UnannInterfaceType_lf_unannClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannInterfaceType_lf_unannClassOrInterfaceType(@NotNull Java8Parser.UnannInterfaceType_lf_unannClassOrInterfaceTypeContext ctx) { } + @Override public void exitUnannInterfaceType_lf_unannClassOrInterfaceType(Java8Parser.UnannInterfaceType_lf_unannClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannInterfaceType_lfno_unannClassOrInterfaceType(@NotNull Java8Parser.UnannInterfaceType_lfno_unannClassOrInterfaceTypeContext ctx) { } + @Override public void enterUnannInterfaceType_lfno_unannClassOrInterfaceType(Java8Parser.UnannInterfaceType_lfno_unannClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannInterfaceType_lfno_unannClassOrInterfaceType(@NotNull Java8Parser.UnannInterfaceType_lfno_unannClassOrInterfaceTypeContext ctx) { } + @Override public void exitUnannInterfaceType_lfno_unannClassOrInterfaceType(Java8Parser.UnannInterfaceType_lfno_unannClassOrInterfaceTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannTypeVariable(@NotNull Java8Parser.UnannTypeVariableContext ctx) { } + @Override public void enterUnannTypeVariable(Java8Parser.UnannTypeVariableContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannTypeVariable(@NotNull Java8Parser.UnannTypeVariableContext ctx) { } + @Override public void exitUnannTypeVariable(Java8Parser.UnannTypeVariableContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterUnannArrayType(@NotNull Java8Parser.UnannArrayTypeContext ctx) { } + @Override public void enterUnannArrayType(Java8Parser.UnannArrayTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitUnannArrayType(@NotNull Java8Parser.UnannArrayTypeContext ctx) { } + @Override public void exitUnannArrayType(Java8Parser.UnannArrayTypeContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterMethodDeclaration(@NotNull Java8Parser.MethodDeclarationContext ctx) { } + @Override public void enterMethodDeclaration(Java8Parser.MethodDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitMethodDeclaration(@NotNull Java8Parser.MethodDeclarationContext ctx) { } + @Override public void exitMethodDeclaration(Java8Parser.MethodDeclarationContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterMethodModifiers(@NotNull Java8Parser.MethodModifiersContext ctx) { } + @Override public void enterMethodModifiers(Java8Parser.MethodModifiersContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitMethodModifiers(@NotNull Java8Parser.MethodModifiersContext ctx) { } + @Override public void exitMethodModifiers(Java8Parser.MethodModifiersContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterMethodModifier(@NotNull Java8Parser.MethodModifierContext ctx) { } + @Override public void enterMethodModifier(Java8Parser.MethodModifierContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitMethodModifier(@NotNull Java8Parser.MethodModifierContext ctx) { } + @Override public void exitMethodModifier(Java8Parser.MethodModifierContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterMethodHeader(@NotNull Java8Parser.MethodHeaderContext ctx) { } + @Override public void enterMethodHeader(Java8Parser.MethodHeaderContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitMethodHeader(@NotNull Java8Parser.MethodHeaderContext ctx) { } + @Override public void exitMethodHeader(Java8Parser.MethodHeaderContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterResult(@NotNull Java8Parser.ResultContext ctx) { } + @Override public void enterResult(Java8Parser.ResultContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void exitResult(@NotNull Java8Parser.ResultContext ctx) { } + @Override public void exitResult(Java8Parser.ResultContext ctx) { } /** * {@inheritDoc} * * <p>The default implementation does nothing.</p> */ - @Override public void enterMethodDeclarator(@NotNull Java8Parser.M... [truncated message content] |
From: <dal...@us...> - 2022-10-11 22:06:30
|
Revision: 25612 http://sourceforge.net/p/jedit/svn/25612 Author: daleanson Date: 2022-10-11 22:06:28 +0000 (Tue, 11 Oct 2022) Log Message: ----------- ant test file for json parser Added Paths: ----------- plugins/Beauty/trunk/ant_json_test.xml Added: plugins/Beauty/trunk/ant_json_test.xml =================================================================== --- plugins/Beauty/trunk/ant_json_test.xml (rev 0) +++ plugins/Beauty/trunk/ant_json_test.xml 2022-10-11 22:06:28 UTC (rev 25612) @@ -0,0 +1,93 @@ +<project name="java_test" default="test" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless"> + <!-- ======================================================================== + Target: set classpath + ========================================================================= --> + <target name="setClasspath"> + <path id="classpathref"> + <!-- required locations/jars --> + <pathelement location="${classes.dir}" /> + <pathelement path="${java.class.path}"/> + + <!-- required for jEdit plugin --> + <pathelement location="${jedit.install.dir}/jedit.jar" /> + + <!-- dependencies --> + <pathelement location="${jedit.plugins.dir}/kappalayout.jar"/> + <pathelement location="${jedit.plugins.dir}/antlr-4.10.1-complete.jar"/> + </path> + </target> + + <!-- ======================================================================= + NOTE: THESE TESTS EXEC THE SYSTEM DIFF!!! THEY WILL FAIL IF DIFF IS + NOT INSTALLED OR NOT ON THE PATH!!! + + TODO: change out the echos with a fail. + ======================================================================== --> + <target name="test" depends="test1, test2, test3, test4"> + </target> + + <target name="test1" depends="setClasspath"> + <java classname="beauty.parsers.json.JSONBeautyListener" fork="true" output="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/after/test1.json"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/before/test1.json"/> + </java> + <exec executable="diff" outputproperty="test1diff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/after/test1.json"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/expected/test1.json"/> + </exec> + <condition property="test1" value="true"> + <equals arg1="${test1diff}" arg2=""/> + </condition> + <echo if:set="test1">test1 passed</echo> + <echo unless:set="test1">test1 failed: ${test1diff}</echo> + </target> + + <target name="test2" depends="setClasspath"> + <java classname="beauty.parsers.json.JSONBeautyListener" fork="true" output="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/after/test2.json" > + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/before/test2.json"/> + </java> + <exec executable="diff" outputproperty="test2diff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/after/test2.json"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/expected/test2.json"/> + </exec> + <condition property="test2" value="true"> + <equals arg1="${test2diff}" arg2=""/> + </condition> + <echo if:set="test2">test2 passed</echo> + <echo unless:set="test2">test2 failed: ${test2diff}</echo> + </target> + + <target name="test3" depends="setClasspath"> + <java classname="beauty.parsers.json.JSONBeautyListener" fork="true" output="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/after/test3.json"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/before/test3.json"/> + </java> + <exec executable="diff" outputproperty="test3diff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/after/test3.json"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/expected/test3.json"/> + </exec> + <condition property="test3" value="true"> + <equals arg1="${test3diff}" arg2=""/> + </condition> + <echo if:set="test3">test3 passed</echo> + <echo unless:set="test3">test3 failed: ${test3diff}</echo> + </target> + + <target name="test4" depends="setClasspath"> + <java classname="beauty.parsers.json.JSONBeautyListener" fork="true" output="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/after/test4.json" > + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/before/test4.json"/> + </java> + <exec executable="diff" outputproperty="test4diff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/after/test4.json"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/json/expected/test4.json"/> + </exec> + <condition property="test4" value="true"> + <equals arg1="${test4diff}" arg2=""/> + </condition> + <echo if:set="test4">test4 passed</echo> + <echo unless:set="test4">test4 failed: ${test4diff}</echo> + </target> + +</project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-10-02 03:25:48
|
Revision: 25610 http://sourceforge.net/p/jedit/svn/25610 Author: daleanson Date: 2022-10-02 03:25:43 +0000 (Sun, 02 Oct 2022) Log Message: ----------- java 17- test files Added Paths: ----------- plugins/Beauty/trunk/test/test_files/ plugins/Beauty/trunk/test/test_files/java/ plugins/Beauty/trunk/test/test_files/java/after/ plugins/Beauty/trunk/test/test_files/java/after/AllInOne11.java plugins/Beauty/trunk/test/test_files/java/after/AllInOne17.java plugins/Beauty/trunk/test/test_files/java/after/AllInOne8.java plugins/Beauty/trunk/test/test_files/java/after/BasicClass.java plugins/Beauty/trunk/test/test_files/java/after/BasicClass3.java plugins/Beauty/trunk/test/test_files/java/after/BlockTest.java plugins/Beauty/trunk/test/test_files/java/after/Comments.java plugins/Beauty/trunk/test/test_files/java/after/Comments2.java plugins/Beauty/trunk/test/test_files/java/after/Element1.java plugins/Beauty/trunk/test/test_files/java/after/EnumTest.java plugins/Beauty/trunk/test/test_files/java/after/IF_PERMITS.java plugins/Beauty/trunk/test/test_files/java/after/Ids.java plugins/Beauty/trunk/test/test_files/java/after/ImportsAndAnnos.java plugins/Beauty/trunk/test/test_files/java/after/ManyStringsConcat.java plugins/Beauty/trunk/test/test_files/java/after/PatternMatching4instanceof.java plugins/Beauty/trunk/test/test_files/java/after/PatternMatching4switchExp.java plugins/Beauty/trunk/test/test_files/java/after/Pizza.java plugins/Beauty/trunk/test/test_files/java/after/Records.java plugins/Beauty/trunk/test/test_files/java/after/SealedClasses.java plugins/Beauty/trunk/test/test_files/java/after/SwitchExpressions.java plugins/Beauty/trunk/test/test_files/java/after/TextBlocks.java plugins/Beauty/trunk/test/test_files/java/after/Yield.java plugins/Beauty/trunk/test/test_files/java/after/module-info.java plugins/Beauty/trunk/test/test_files/java/after/outer.java plugins/Beauty/trunk/test/test_files/java/before/ plugins/Beauty/trunk/test/test_files/java/before/AllInOne11.java plugins/Beauty/trunk/test/test_files/java/before/AllInOne17.java plugins/Beauty/trunk/test/test_files/java/before/AllInOne7.java plugins/Beauty/trunk/test/test_files/java/before/AllInOne8.java plugins/Beauty/trunk/test/test_files/java/before/BasicClass.java plugins/Beauty/trunk/test/test_files/java/before/BasicClass3.java plugins/Beauty/trunk/test/test_files/java/before/BlockTest.java plugins/Beauty/trunk/test/test_files/java/before/Comments.java plugins/Beauty/trunk/test/test_files/java/before/Comments2.java plugins/Beauty/trunk/test/test_files/java/before/Element1.java plugins/Beauty/trunk/test/test_files/java/before/EnumTest.java plugins/Beauty/trunk/test/test_files/java/before/EnumTest2.java plugins/Beauty/trunk/test/test_files/java/before/IF_PERMITS.java plugins/Beauty/trunk/test/test_files/java/before/Ids.java plugins/Beauty/trunk/test/test_files/java/before/ImportsAndAnnos.java plugins/Beauty/trunk/test/test_files/java/before/ManyStringsConcat.java plugins/Beauty/trunk/test/test_files/java/before/ModuleTest.java plugins/Beauty/trunk/test/test_files/java/before/PatternMatching4instanceof.java plugins/Beauty/trunk/test/test_files/java/before/PatternMatching4switchExp.java plugins/Beauty/trunk/test/test_files/java/before/Pizza.java plugins/Beauty/trunk/test/test_files/java/before/Records.java plugins/Beauty/trunk/test/test_files/java/before/SealedClasses.java plugins/Beauty/trunk/test/test_files/java/before/SwitchExpressions.java plugins/Beauty/trunk/test/test_files/java/before/SwitchTest.java plugins/Beauty/trunk/test/test_files/java/before/TextBlocks.java plugins/Beauty/trunk/test/test_files/java/before/Yield.java plugins/Beauty/trunk/test/test_files/java/before/module-info.java plugins/Beauty/trunk/test/test_files/java/before/outer.java plugins/Beauty/trunk/test/test_files/java/expected/ plugins/Beauty/trunk/test/test_files/java/expected/AllInOne11.java plugins/Beauty/trunk/test/test_files/java/expected/AllInOne17.java plugins/Beauty/trunk/test/test_files/java/expected/AllInOne8.java plugins/Beauty/trunk/test/test_files/java/expected/BasicClass.java plugins/Beauty/trunk/test/test_files/java/expected/BasicClass3.java plugins/Beauty/trunk/test/test_files/java/expected/BlockTest.java plugins/Beauty/trunk/test/test_files/java/expected/Comments.java plugins/Beauty/trunk/test/test_files/java/expected/Comments2.java plugins/Beauty/trunk/test/test_files/java/expected/Element1.java plugins/Beauty/trunk/test/test_files/java/expected/EnumTest.java plugins/Beauty/trunk/test/test_files/java/expected/IF_PERMITS.java plugins/Beauty/trunk/test/test_files/java/expected/Ids.java plugins/Beauty/trunk/test/test_files/java/expected/ImportsAndAnnos.java plugins/Beauty/trunk/test/test_files/java/expected/ManyStringsConcat.java plugins/Beauty/trunk/test/test_files/java/expected/PatternMatching4instanceof.java plugins/Beauty/trunk/test/test_files/java/expected/PatternMatching4switchExp.java plugins/Beauty/trunk/test/test_files/java/expected/Pizza.java plugins/Beauty/trunk/test/test_files/java/expected/Records.java plugins/Beauty/trunk/test/test_files/java/expected/SealedClasses.java plugins/Beauty/trunk/test/test_files/java/expected/SwitchExpressions.java plugins/Beauty/trunk/test/test_files/java/expected/TextBlocks.java plugins/Beauty/trunk/test/test_files/java/expected/Yield.java plugins/Beauty/trunk/test/test_files/java/expected/module-info.java plugins/Beauty/trunk/test/test_files/java/expected/outer.java Index: plugins/Beauty/trunk/test/test_files/java/after =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after 2022-10-02 03:23:12 UTC (rev 25609) +++ plugins/Beauty/trunk/test/test_files/java/after 2022-10-02 03:25:43 UTC (rev 25610) Property changes on: plugins/Beauty/trunk/test/test_files/java/after ___________________________________________________________________ Added: svn:ignore ## -0,0 +1 ## +after Added: plugins/Beauty/trunk/test/test_files/java/after/AllInOne11.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/AllInOne11.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/AllInOne11.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,271 @@ +package var.var; + +import java.lang.annotation.*; +import java.util.ArrayList; +import java.util.List; + +import var.var.base.T; + + +class Tests { + class AC implements AutoCloseable { + @Override + public void close() throws Exception { + } + + } + + class TT extends var.var.base.T implements var.var.base.I { + <T extends var.var.base.I> void f() { + } + + @Override + public void f1() { + } + + void var() { + var: + for (;;) { + break var; + } + } + + } + + interface II { + void var (); + } + + enum E1 { + var (1); + + E1(int i) { + } + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.METHOD}) + public @interface TM1 { + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE}) + public @interface TM2 { + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.MODULE, ElementType.TYPE_USE}) + public @interface TM3 { + } + + static class PF { + protected int p; + + static int sp; + + static int var; + + } + + static class CCC { + static int var = 0; + + static int var() { + return 0; + } + + } + + { + final var c = 1; + PF.sp = c; + T t; + var var = 1; + var = var + var; + var b = (byte) var; + var r = var(); + var v = CCC.var; + var n = CCC.var() + CCC.var; + CI4 ci4 = new CI4(); + I4 i4a = ci4 :: var; + E1 e = E1.var; + switch (e) { + case var: + break; + } + } + + { + int var, i = 1; + } + + { + var var = new PF(); + var.var = 1; + } + + private int var = 1; + + int var() { + return 0; + } + + + static { + final var c = 1; + PF.sp = c; + } + { + var var = "var"; + var module = "module"; + var open = "open"; + var requires = "requires"; + var exports = "exports"; + var opens = "opens"; + var to = "to"; + var uses = "uses"; + var provides = "provides"; + var with = "with"; + var transitive = "transitive"; + } + + void foo() { + var f = 1; + } + + void foo2() throws Exception { + try (var a = new AC()) { + for (final var i = 1;;) { + break; + } + + for (final var var = 1;;) { + break; + } + List<Integer> lst = new ArrayList<>(); + + for (final var item : lst) { + } + + for (final var var : lst) { + } + } + } + + void foo3() throws Exception { + var a = new AC(); + try (a) { + } + } + + void foo31() throws Exception { + var var = new AC(); + var a = new AC(); + try ( + a; + var ) { + } + } + + void foo4() { + I1 i1a = (int i ) -> 1; + I1 i1b = (var var ) -> 1; + I1 i1c = var -> 1; + I2 i2a = (final int var, int var1 ) -> 1; + I2 i2b = (final var var, var j ) -> 1; + } + + interface I1 { + int m (int i); + } + + interface I2 { + int m2 (int i, int j); + } + + interface I3 { + void m0 (); + + default void m1 (){ + } + + private void m2 (){ + } + + private <T> void gm2 (T t){ + } + + private static void m3 (){ + } + + static void m4 (){ + } + } + + interface I4 { + int var (); + } + + interface I6 { + default <TT, UU> void var (){ + } + } + + class CI4 implements I4 { + @Override + public int var() { + return 0; + } + + } + + class CI6 implements I6 { + public void vartest() { + I6.super.var(); + + I6.super.<Byte, Long>var(); + } + + } + + class D extends CI4 { + public int var() { + return super.var(); + } + + void f(int var) { + } + + } + + static class Annos { + @interface InnerAnnotation { + int var() default 0; + } + + @interface OuterAnnotation { + InnerAnnotation var() default @InnerAnnotation(var = 1); + } + + } + + static class TH { + void var() { + } + + int var = 1; + + TH() { + this.var(); + this.var = 1; + System.out.println(var); + } + + } + +/* + */ +} Added: plugins/Beauty/trunk/test/test_files/java/after/AllInOne17.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/AllInOne17.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/AllInOne17.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,681 @@ +package var.var.sealed; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; + + +@interface Dummy { +} +@interface Dummy2 { +} +@Target({ElementType.TYPE, ElementType.TYPE_USE}) +@interface Dummy3 { +} +/** + * https://openjdk.java.net/jeps/361 + */ +class SwitchExpressions { + private static final int C = 10; + + static class SC1 { + static final int C = 100; + + } + + enum E1 { + ONE; + + } + + int fn1(int n) { + final int k = 4; + var r = switch (n) { + case 1, 2, 3 + 3, k, C, SC1.C -> 3 + SC1.C; + case 20 -> 3 + 4 + C - k; + case 21 -> + { + int ff = 222; + yield ff; + } + case 22 -> + { + yield 33 + 3; + } + case 99 -> + { + throw new RuntimeException(""); + } + default -> 0; + }; + return r; + } + + String fn2(String s) { + return switch (s) { + // case null -> "n"; + case "a" -> ""; + case "b", "c" -> "a"; + default -> "o"; + }; + } + + int fn3(final int var) { + return switch (var) { + case 1 -> 2; + default -> var; + }; + } + + void fn4() { + fn1( + switch (1) { + case 1 -> 0; + case 2 -> 2; + default -> 1; + } + ); + } + + int fn5() { + E1 e = E1.ONE; + return switch (e) { + case ONE -> 0; + // default -> 1; + }; + } + + void fn6() { + switch (1) { + case 1 -> + { + } + } + } + + void fn7() { + switch (1) { + case 1 -> + { + } + case 2 -> + { + } + } + } + + void fn8() { + var i = 1; + switch (1) { + } + var f = 2; + + switch (2) { + case 2 -> + { + f = 3; + } + } + } + + void fn9(String s) { + switch (s) { + case "" -> + { + } + default -> { + } + } + } + + void fn10() { + var i = switch (1) { + case 1 -> + + switch (2) { + case 2 -> 0; + default -> 2; + }; + default -> 2; + }; + } + + void fn11() { + switch (1) { + case 1 -> throw new RuntimeException(""); + } + } + + int fn12() { + var v = 1; + int n = switch (1) { + case 1 : + var g = 1; + System.out.println(); + yield v; + default : yield 3; + }; + return n; + } + + void fn13() { + int n; + + switch (1) { + case 1 -> n = 1; + } + } + + void fn14() { + switch (1) { + default -> { + } + } + var n = 1; + var m = switch (n) { + case 1 -> 2; + case 2 -> 2; + default -> 1; + }; + m = switch (n) { + case 2 : yield 2; + default : yield 3; + }; + } + +} + +/** + * https://openjdk.java.net/jeps/394 + */ +class PatternMatching4instanceof { + void fn1(Number n) { + if (n instanceof Long var) { + var v = var; + } + else if (n instanceof Integer open) { + var v = open; + } + else if (n instanceof Byte) { + // + } + else { + throw new RuntimeException(""); + } + + if (!(n instanceof Long l)) { + ; + } + + if (n instanceof @Dummy @Dummy2 final Long l && l.byteValue() == 1 || n instanceof @Dummy @Dummy2 final Byte b && b.intValue() == 1) { + ; + } + + if (n instanceof Long) { + ; + } + + if (n instanceof Long var) { + ; + } + + if (n instanceof Long l) { + ; + } + + if (n instanceof final Long l) { + ; + } + + if (n instanceof @Dummy Long l) { + ; + } + + if (n instanceof @Dummy @Dummy2 Long l) { + ; + } + + if (n instanceof @Dummy final Long l) { + ; + } + + if (n instanceof @Dummy @Dummy2 final Long l) { + ; + } + + if (n instanceof @Dummy final Long l) { + ; + } + + if (n instanceof @Dummy @Dummy2 final Long l) { + ; + } + } + +} + +/** + * https://openjdk.java.net/jeps/406 + */ +class PatternMatching4switchExp { + void f(int i) { + } + + void f1(Object obj) { + switch (obj) { + case null -> f(0); + case String s -> f(1); + case int [] a -> f(2); + default -> f(-1); + } + } + + void f2(Object obj) { + switch (obj) { + case null -> f(0); + case Long l -> f(1); + case Integer i -> f(1); + case int [] a -> f(2); + default -> f(-1); + } + } + + void f3(Object o) { + switch (o) { + case null: + case Long l: + f(0); + break; + + default: + break; + } + } + + enum E1 { + var; + + } + + void f4() { + var var = E1.var; + switch (var) { + case var: + return; + + default: + break; + } + + switch (var) { + case var -> + { + } + default -> { + } + } + } + + int f5(Number n) { + return switch (n) { + case Long l && l.intValue() == 1 && l.byteValue() == 1 -> l.byteValue(); + case Long var -> var.byteValue(); + case Integer i -> i.byteValue(); + default -> throw new RuntimeException(""); + }; + } + + Function<Integer, String> f6(Object obj) { + boolean b = true; + return switch (obj) { + case String var && b -> t -> var; + default -> t -> "Default string"; + }; + } + + int dummy() { + return 0; + } + + Function<Integer, String> f7(Object obj) { + boolean b = true; + boolean b2 = true; + boolean b3 = true; + return switch (obj) { + case (((String s) && (b && b2)) && s.length() > 0 && dummy() == 1) -> t -> s; + case (((Integer i && b && b2) && (b && b2)) && b3 && (b && b2)) -> t -> ""; + case (((Integer i && b && b2) && (b && b2)) && b3 && (b && b2 && !b3)) -> + { + yield t -> ""; + } + case final Long l && (b ? b2 : b3) -> + { + yield t -> ""; + } + default -> t -> "Default string"; + }; + } + + void f8(Object o, int i) { + switch (i) { + case 1, 2 : + + case 3, 4 : + { + } + } + switch (o) { + case Number b: + { + } + + default: + { + } + } + var f = switch (o) { + case final I2 l : + { + yield switch (o) { + case Byte b -> 1; + default -> 0; + }; + } + default : { + yield 1; + } + }; + } + +} + +/** + * https://openjdk.java.net/jeps/395 + */ +class Records { + interface I1 { + } + + final record R1(@Dummy2 @Dummy int x) { + R1(int x) { + this.x = x; + } + + enum E { + ONE; + + record ER() { + } + } + + class C { + record CR() { + } + + } + + interface I { + record IR (){ + } + } + + private static final record R() implements I1 { + } + + protected static final record R2() implements I1 { + } + + public static final record R3() implements I1 { + } + + static final record R4() implements I1 { + } + + } + + record R2() { + public @interface TM1 { + record AR() { + } + } + + } + + record R3(int x, T y) { + } + + record R4(int x, T y) implements I1 { + } + + void fn1() { + final record Pt(int x, int y) implements I1, R1.I { + void fn(T t) { + } + + <TT> void f() { + } + + // final int x; implicitly defined + Pt(int x, int y) { + this.x = x; + this.y = y; + } + + // private int c = 1; not allowed + private static final int C = 1; //allowed + + static class C { + } + + } + Pt<Long, Long> p = new Pt<>(1, 2); + p.fn(1L); + } + +} + +/** + * https://openjdk.java.net/jeps/378 + */ +class TextBlocks { + void f(String s) { + } + + void fn() { + var s = """ + a \t + \r"""; + var s2 = """ + a""" + """ + b"""; + var s3 = """ + """; + f(""" + a"""); + f(""" + """); + } + +} + +/** + * https://openjdk.java.net/jeps/409 + */ +class SealedClasses { + interface I1 { + } + + class C0 { + } + + sealed class SC1 extends C0 implements I1 permits FC1, FC2 { + } + + sealed class SC2 { + void f() { + var non = 1; + var sealed = 2; + var ns = non - sealed; + var permits = 1; + var record = 1; + } + + } + + final class FC1 extends SC1 { + } + + final class FC2 extends SC1 { + } + + non-sealed class NSC1 extends SC2 { + } + + class C1 extends NSC1 { + } + +} + +class Ids { + class oo { + class opens <T> { + enum E { + provides; + + } + + class provides <S> { + void f() { + opens<Byte>.provides<Long> b1 = new opens<>().new provides<>() { + }; + opens<Byte>.provides<Long> b2 = new opens().new provides() { + }; + } + + void g() { + E e = E.provides; + switch (e) { + case provides: + break; + } + } + + <T> Object var() { + return null; + } + + provides<Long> get() { + return null; + } + + class with <S> { + } + + static class SS <R> { + interface Sup <T> { + T get (); + } + + } + + void h() { + var o = get().<Long> var(); + SS.Sup<provides<Long>.with<Long>> s = @Issue1897.Dum1 provides<Long>.with<Long> :: new; + } + + class R { + <to> void f() { + } + + } + + } + + } + + } + + static class opens { + enum requires { + opens; + + } + + public static <T> void with(String s) { + } + + interface with { + default void f (){ + } + } + + class exports implements with { + void g() { + with.super.f(); + } + + } + + @interface to { + } + + class module { + public static <T> void with(String s) { + try { + } + catch ( Exception var) { + } + } + + } + + record provides(int to) { + void f() { + opens o = new opens(); + BiFunction<Long, Long, Long> b = (opens, with) -> 1L; + Consumer<String> c = opens.module :: <Byte> with; + } + + } + + } + +} + +class Yield { + int f(Object o) { + final var yield = 1; + return switch (o) { + case Long l -> + { + // var yield = 1; + yield yield; + } + default -> { + yield yield; + } + }; + } + + int yield(int yield) { + return yield; + } + +} + +class IF_PERMITS { + final class T1 implements I1 { + } + + final class T2 implements I1 { + } + + interface I2 { + } + + sealed interface I1 extends I2 permits T1, T2 { + } + +} Added: plugins/Beauty/trunk/test/test_files/java/after/AllInOne8.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/AllInOne8.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/AllInOne8.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,282 @@ +// Source: https://en.wikipedia.org/wiki/Java_syntax +// Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html +// Lambdas +public class Lambdas { + public static void main(String [] args) { + // use predicate composition to remove matching names + List<Name> list = new ArrayList<>(); + + for ( Name name : NAMES) { + list.add(name); + } + Predicate<Name> pred1 = name -> "Sally".equals(name.firstName); + Predicate<Name> pred2 = name -> "Queue".equals(name.lastName); + list.removeIf(pred1.or(pred2)); + printNames("Names filtered by predicate:", list.toArray(new Name[list.size()])); + Comparator<Name> com1 = Comparator.comparing((Name name1 ) -> name1.lastName).thenComparing(name2 -> name2.firstName); + Comparator<Name> com2 = Comparator.<Name, String> comparing(name1 -> name1.lastName).thenComparing(name2 -> name2.firstName); + // sort array using lambda expression + copy = Arrays.copyOf(NAMES, NAMES.length); + Arrays.sort(copy, (a, b) -> a.compareTo(b)); + printNames("Names sorted with lambda expression:", copy); + } + +} + +class LambdaAndCastWithBounds { + interface I1 <T> { + void fn (); + } + + interface I2 { + void fn (); + } + + I1<Byte> i1 = (I1<Byte> & Serializable & Cloneable) () -> { + }; + + I2 i2 = (I2 & Serializable & Cloneable) () -> { + }; + +} + +// Default interface method +interface Formula { + double calculate (int a); + + default double sqrt (int a){ + return Math.sqrt(a); + } +} + +// Double colon +public class For { + public void bar() { + Function<Computer, Integer> getAge = Computer :: getAge; + Integer computerAge = getAge.apply(c1); + Function<Computer, Integer> getAgeAlt = this :: getAge; + Function<Computer, Integer> getAgeAlt2 = MyClass.this :: getAge; + Function<Computer, Integer> getAgeAlt3 = generate() :: getAge; + Function<Computer, Integer> getAgeAlt4 = MyClass.generate() :: getAge; + Function<Computer, Integer> getAgeAlt5 = MyClass.twice().nested() :: getAge; + Function<Computer, Integer> getAgeAlt6 = twice().nested() :: getAge; + Function<Computer, Integer> getAgeAlt7 = this.singletonInstanceMethod :: get; + autodetect(this.beans, ((AutodetectCapableMBeanInfoAssembler) this.assembler) :: includeBean); + TriFunction<Integer, String, Integer, Computer> c6Function = Computer :: new; + Computer c3 = c6Function.apply(2008, "black", 90); + Function<Integer, Computer []> computerCreator = Computer [] :: new; + Computer [] computerArray = computerCreator.apply(5); + } + +} + +// Type Annotations +public class Annotations { + @Valid + private List<@NotNull String> property; + +} + +public interface CallableProcessingInterceptor { + default <T> void beforeConcurrentHandling (NativeWebRequest request, Callable<T> task)throws Exception { + } +} + +@FunctionalInterface +public interface RouterFunction <T extends ServerResponse> { + default <S extends ServerResponse> RouterFunction<S> filter (HandlerFilterFunction<T, S> filterFunction){ + return new RouterFunctions.FilteredRouterFunction<>(this, filterFunction); + } +} + +// Instanceof +class InstanceOf { + public static void main(String [] args) { + if (args instanceof String []) { + } + + if (args instanceof a.String []) { + } + } + +} + +// Unicode +class Unicode { + public static void main(String [] args) { + System.out.println("A = \uuu0041"); + } + +} + +// More Annotations +public class Annos { + public @interface Dummy4 { + String [] value(); + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + public @interface Dummy03 { + Dummy3 [] value(); + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + public @interface Dummy01 { + Dummy1 [] value(); + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + @Repeatable(Dummy01.class) + public @interface Dummy1 { + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + public @interface Dummy2 { + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + @Repeatable(Dummy03.class) + public @interface Dummy3 { + } + + @Dummy4("#1") + @Dummy1 + @Dummy3 + public static <T extends @Dummy2 @Dummy3 Object> @Dummy1 @Dummy3 T @Dummy1 @Dummy3 [] foo(@Dummy1 T @Dummy2 @Dummy3 [] arr, @Dummy1 @Dummy3 T @Dummy1 @Dummy3... t) { + return (@Dummy1 @Dummy3 T []) null; + } + + @Dummy4("") + public static <@Dummy1 @Dummy2 T extends @Dummy1 @Dummy3 Object> @Dummy1 @Dummy3 T @Dummy1 @Dummy3 [] @Dummy1 @Dummy2 [] foo2(@Dummy1 T @Dummy2 @Dummy3 [] @Dummy1 @Dummy3 [] arr) { + return (@Dummy1 @Dummy2 T [] @Dummy1 @Dummy2 []) null; + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.METHOD}) + public @interface TM1 { + } + + class Gen <T> { + } + + class A <@Dummy1 T extends @Dummy1 Gen<@Dummy1 T>> { + } + + public static <@Dummy3 T> void foo3(T t, Gen<@Dummy1 @Dummy3 ? super @Dummy1 @Dummy3 T> c) { + } + + public static <@Dummy3 T> void foo33(T t, Gen<@Dummy1 @Dummy3 ?> c) { + } + + public static <@Dummy3 T, @Dummy1 S> void foo333(T t, Gen<@Dummy1 @Dummy3 T @Dummy1 []> c) { + } + + @Dummy3 + public static <@Dummy3 T extends @Dummy3 Gen<@Dummy1 ? super @Dummy1 T>> @Dummy3 T @Dummy3 [] f(@Dummy3 T @Dummy3... t) { + return (@Dummy3 T @Dummy3 []) null; + } + + interface TI1 { + @TM1 + public void im01 (); + + public <@Dummy3 T> @TM1 @TM2 T gim01 (@TM1 T t); + } + + static class Issue2454 { + interface I { + default <T> void fn1 (){ + } + + default <T, S, U> void fn2 (){ + } + } + + class C implements I { + public void test() { + I.super.<Long>fn1(); // fix #2454 + + I.super.fn1(); //ok + + I.super.<List<Integer>, Byte, Map<Long, String>>fn2(); // fix #2454 + + I.super.fn2(); //ok + } + + } + + } + +} + +class Issue1897 { + @Target({ElementType.TYPE, ElementType.TYPE_USE}) + @interface Dum1 { + } + + @Target(ElementType.TYPE_USE) + @interface Dum2 { + } + + @Target(ElementType.TYPE_USE) + @Retention(RetentionPolicy.RUNTIME) + @interface Dum3 { + } + + abstract class C { + // https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.1 + void f(@Dum1 @Dum2 C this) { + } + + void d(C this, int i, int j ) { + } + + void e(C this, int i, int j, int... k) { + } + + void c(C this, int... k) { + } + + abstract void am(C this) ; + + class D { + class E { + E(Issue1897.C.D D.this) { + } + + } + + class GE { + <TY> GE(Issue1897.C.D D.this) { + } + + } + + void b(Issue1897.C.@Dum3 D Issue1897.C.D.this) { + } + + void b2(Issue1897.C.@Dum3 D this) { + } + + void b3(@Dum1 D this) { + } + + } + + void b(Issue1897.C Issue1897.C.this) { + } + + } + +} Added: plugins/Beauty/trunk/test/test_files/java/after/BasicClass.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/BasicClass.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/BasicClass.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,55 @@ +package blah.var.foo; + +import java.lang.annotation.ElementType; +import java.util.*; + + +public class BasicClass { + // a field + /* why */ private static final int C = 10; + + // a method + public int getC() { + switch (C) { + case 1: + // what + return ++C; + case 2: + // do something + y = C + z; + break; + case 3: + + default: + return c; + } + return C; + } + + // a class + static class SC1 { + static final int C = 100; + + } + + // an enum + enum E1 { + ONE, TWO, THREE; + + Color() { + colorMap.put(toString(), this); + } + } + + void fn4() { + // a switch expression + fn1( + switch (1) { + case 1 -> 0; + case 2 -> 2; + default -> 1; + } + ); + } + +} Added: plugins/Beauty/trunk/test/test_files/java/after/BasicClass3.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/BasicClass3.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/BasicClass3.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,642 @@ +// Source: https://en.wikipedia.org/wiki/Java_syntax +// Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html +/* This is a multi-line comment. + * It may occupy more than one line. */ +// This is an end-of-line comment + +/** + * This is a documentation comment. + * + * @author John Doe + */ +package myapplication.mylibrary; + +import java.util.Random; // Single type declaration + +import java.*; +import static java.lang.System.out; //'out' is a static field in java.lang.System +import java.util.*; + +import static screen.ColorName.*; + + +public enum ColorName { + RED, BLUE, GREEN +}; + +// See http://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html +public class LexerTest { + static void main(String [] args) { + long creditCardNumber = 1234_5678_9012_3456L; + long socialSecurityNumber = 999_99_9999L; + float pi = 3.14_15F; + long hexBytes = 0xFF_EC_DE_5E; + long hexWords = 0xCAFE_BABE; + long maxLong = 0x7fff_ffff_ffff_ffffL; + byte nybbles = 0b0010_0101; + long bytes = 0b11010010_01101001_10010100_10010010; + long lastReceivedMessageId = 0L; + double hexDouble1 = 0x1.0p0; + double hexDouble2 = 0x1.956ad0aae33a4p117; + int octal = 01234567; + long hexUpper = 0x1234567890ABCDEFL; + long hexLower = 0x1234567890abcedfl; + int x1 = _52; // This is an identifier, not a numeric literal + int x2 = 5_2; // OK (decimal literal) + int x4 = 5_______2; // OK (decimal literal) + int x7 = 0x5_2; // OK (hexadecimal literal) + int x9 = 0_52; // OK (octal literal) + int x10 = 05_2; // OK (octal literal) + int x, y, result; + // Arithmetic operators + result = x + y; + result = x - y; + result = x * y; + result = y / x; + result = x % 3; + // Unary operators + result = +x; + result = -y; + result = ++x; + result = --y; + boolean ok = false; + boolean not_ok = !ok; + // assignments yield a value + (result = System.class).getName(); + // Prefix & postfix + ++x; + x++; + --y; + y--; + LexerTest.prePost++; + LexerTest.prePost--; + myapplication.mylibrary.LexerTest.prePost++; + myapplication.mylibrary.LexerTest.prePost--; + this.prePost++; + this.prePost--; + super.prePost++; + super.prePost--; + someMethod()[0]++; + someMethod()[0]--; + ++LexerTest.prePost; + --LexerTest.prePost; + ++myapplication.mylibrary.LexerTest.prePost; + --myapplication.mylibrary.LexerTest.prePost; + ++this.prePost; + --this.prePost; + ++super.prePost; + --super.prePost; + ++someMethod()[0]; + --someMethod()[0]; + // Relational operators + result = x == y; + result = x != y; + result = x > y; + result = x >= y; + result = x < y; + result = x <= y; + + // Conditional operators + if ((x > 8) && (y > 8)) { + } + + if ((x > 10) || (y > 10)) { + } + result = (x > 10) ? x : y; + // Ternary operator right associativity + int f = b1 ? b2 : b3 ? 3 : 4; + // Bitwise and Bit shift operators + result = ~x; + result = x << 1; + result = x >> 2; + result = x >>> 3; + result = x & 4; + result = x ^ 5; + result = x | 6; + // Assignment operators + result = x; + result += x; + result -= x; + result *= x; + result /= x; + result %= x; + result &= x; + result ^= x; + result |= x; + result <<= x; + result >>= x; + result >>>= x; + } + + public static void methodCalls() { + new Object().getClass().hashCode(); + new String[]{"test"}[0].getLength(); + String [] strings; + (strings = new String[]{"test"})[0].charAt(0); + strings[0].length(); + Foo foo = new Foo().new Bar(); + foo.hashCode(); + Foo.class.hashCode(); + new HashMap<Object, String>(5).get(null); + } + +} + +public class ImportsTest { + public static void main(String [] args) { + /* The following line is equivalent to + * java.util.Random random = new java.util.Random(); + * It would've been incorrect without the import declaration */ + Random random = new Random(); + } + +} + +public class HelloWorld { + public static void main(String [] args) { + /* The following line is equivalent to: + * System.out.println("Hello World!"); + * and would have been incorrect without the import declaration. */ + out.println("Hello World!"); + + // Conditional statements ------------------- + if (i == 3) { + doSomething(); + } + + if (i == 2) { + doSomething(); + } + else { + doSomethingElse(); + } + + if (i == 3) { + doSomething(); + } + else if (i == 2) { + doSomethingElse(); + } + else { + doSomethingDifferent(); + } + int a = 1; + int b = 2; + int minVal = (a < b) ? a : b; + // switch + switch (ch) { + case 'A': + doSomething(); // Triggered if ch == 'A' + break; + case 'B': + case 'C': + doSomethingElse(); // Triggered if ch == 'B' or ch == 'C' + break; + + default: + doSomethingDifferent(); // Triggered in any other case + break; + } + // Iteration statements ------------------- + while (i < 10) { + doSomething(); + doAnotherThing(); + } + + do { + doSomething(); + } + while (i < 10); + + for (int i = 0; i < 10; i++) { + doSomething(); + } + + // A more complex loop using two variables + for (int i = 0, j = 9; i < 10; i++, j -= 3) { + doSomething(); + } + + for (;;) { + doSomething(); + } + + for ( int i : intArray) { + doSomething(i); + } + + // Jump statements ------------------- + // Label + start: + someMethod(); + + // break + for (int i = 0; i < 10; i++) { + while (true) { + break; + } + // Will break to this point + } + + outer: + for (int i = 0; i < 10; i++) { + while (true) { + break outer; + } + } + // Will break to this point + // continue + int ch; + while (ch = getChar()) { + if (ch == ' ') { + continue; // Skips the rest of the while-loop + } + // Rest of the while-loop, will not be reached if ch == ' ' + doSomething(); + } + + outer: + for ( String str : stringsArr) { + char [] strChars = str.toCharArray(); + + for ( char ch : strChars) { + if (ch == ' ') { + // Continues the outer cycle and the next + // string is retrieved from stringsArr + continue outer; + } + doSomething(ch); + } + } + + // return + // If streamClosed is true, execution is stopped + if (streamClosed) { + return; + } + readFromStream(); + int result = a + b; + return result; + // Exception handling statements ------------------- + // try-catch-finally + try { + // Statements that may throw exceptions + methodThrowingExceptions(); + } + catch ( Exception ex) { + // Exception caught and handled here + reportException(ex); + } + finally { + // Statements always executed after the try/catch blocks + freeResources(); + } + try { + methodThrowingExceptions(); + } + catch ( IOException | IllegalArgumentException ex) { + // Both IOException and IllegalArgumentException will be caught and handled here + reportException(ex); + } + // try-with-resources statement + try ( + FileOutputStream fos = new FileOutputStream("filename"); + XMLEncoder xEnc = new XMLEncoder(fos) ) { + xEnc.writeObject(object); + } + catch ( IOException ex) { + Logger.getLogger(Serializer.class.getName()).log(Level.SEVERE, null, ex); + } + + // throw + if (obj == null) { + // Throws exception of NullPointerException type + throw new NullPointerException(); + } + // Will not be called, if object is null + doSomethingWithObject(obj); + // Thread concurrency control ------------------- + // Acquires lock on someObject. It must be of a reference type and must be non-null + synchronized (someObject){ + // Synchronized statements + someStatement(); + } + + // assert statement + // If n equals 0, AssertionError is thrown + assert n != 0; + + // If n equals 0, AssertionError will be thrown + // with the message after the colon + assert n != 0 : "n was equal to zero"; + // Reference types ------------------- + // Arrays + int [] numbers = new int[5]; + numbers[0] = 2; + int x = numbers[0]; + // Initializers ------------------- + // Long syntax + int [] XXXXXXXnumbers = new int[]{999, 888, 777, 666, 555}; + // Short syntax + int [] numbers2 = {20, 1, 42, 15, 34}; + // Multi-dimensional arrays + int [] [] numbers = new int[3][3]; + numbers[1][2] = 2; + int [] [] numbers2 = {{2, 3, 2}, {1, 2, 6}, {2, 4, 5}}; + int [] [] numbers = new int[2][]; //Initialization of the first dimension only + numbers[0] = new int[3]; + numbers[1] = new int[2]; + // Prefix & postfix + numbers[0][0]++; + numbers[0][0]--; + ++numbers[0][0]; + --numbers[0][0]; + foo()[0]++; + foo()[0]--; + ++foo()[0]; + --foo()[0]; + } + +} + +// Classes ------------------- +// Top-level class +class Foo { +// Class members +} + +// Inner class +class Foo { // Top-level class + class Bar { // Inner class + } + + static void inner_class_constructor() { + // https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.9 + Foo foo = new Foo(); + Foo.Bar fooBar1 = foo.new Bar(); + Foo.Bar fooBar2 = new Foo().new Bar(); + } + +} + +// Nested class +class Foo { // Top-level class + static class Bar { // Nested class + } + +} + +// Local class +class Foo { + void bar() { + @WeakOuter class Foobar { // Local class within a method + } + } + +} + +// Anonymous class +class Foo { + void bar() { + new Object() { // Creation of a new anonymous class extending Object + }; + } + +} + +// Access modifiers +public class Foo { + int go() { + return 0; + } + + private class Bar { + } + +} + +// Constructors and initializers +class Foo { + String str; + + Foo() { // Constructor with no arguments + // Initialization + } + + Foo(String str) { // Constructor with one argument + this.str = str; + } + +} + +class Foo { + + static { + // Initialization + } +} + +class Foo { + { + // Initialization + } + +} + +// Methods ------------------- +class Foo { + public Foo() { + System.out.println(Foo.class.getName() + ": constructor runtime"); + } + + public Foo(int a, int b) { + System.out.println(Foo.class.getName() + ": overloaded constructor " + this()); + } + + int bar(int a, int b) { + return (a * 2) + b; + } + + /* Overloaded method with the same name but different set of arguments */ + int bar(int a) { + return a * 2; + } + + void openStream() throws IOException, myException { // Indicates that IOException may be thrown + } + + // Varargs + void printReport(String header, int... numbers) { //numbers represents varargs + System.out.println(header); + + for ( int num : numbers) { + System.out.println(num); + } + } + +} + +// Overriding methods +class Operation { + public int doSomething() { + return 0; + } + +} + +class NewOperation extends Operation { + @Override + public int doSomething() { + return 1; + } + +} + +// Abstract classes +public class AbstractClass { + private static final String hello; + + + static { + System.out.println(AbstractClass.class.getName() + ": static block runtime"); + hello = "hello from " + AbstractClass.class.getName(); + } + { + System.out.println(AbstractClass.class.getName() + ": instance block runtime"); + } + + public AbstractClass() { + System.out.println(AbstractClass.class.getName() + ": constructor runtime"); + } + + public static void hello() { + System.out.println(hello); + } + +} + +public class CustomClass extends AbstractClass { + + static { + System.out.println(CustomClass.class.getName() + ": static block runtime"); + } + { + System.out.println(CustomClass.class.getName() + ": instance block runtime"); + } + + public CustomClass() { + super(); + System.out.println(CustomClass.class.getName() + ": constructor runtime"); + } + + public static void main(String [] args) { + CustomClass nc = new CustomClass(); + hello(); + AbstractClass.hello(); //also valid + } + +} + + +// Enumerations ------------------- +enum Season { + WINTER, SPRING, SUMMER, AUTUMN +} +public enum Season { + WINTER ("Cold"), SPRING ("Warmer"), SUMMER ("Hot"), AUTUMN ("Cooler"); + + Season(String description) { + this.description = description; + } + + + private final String description; + + + public String getDescription() { + return description; + } +} +public enum Season { + WINTER { + String getDescription() { + return "cold"; + } + + }, + SPRING { + String getDescription() { + return "warmer"; + } + + }, + SUMMER { + String getDescription() { + return "hot"; + } + + }, + FALL { + String getDescription() { + return "cooler"; + } + + }; + +} +// Interfaces ------------------- +interface ActionListener { + int ACTION_ADD = 0; int ACTION_REMOVE = 1; void actionSelected (int action); +} + +interface RequestListener { + int requestReceived (); +} + +class ActionHandler implements ActionListener, RequestListener { + public void actionSelected(int action) { + } + + public int requestReceived() { + } + +} + +class Dummy { + public void dummy() { + // Calling method defined by interface + RequestListener listener = new ActionHandler(); /*ActionHandler can be + represented as RequestListener...*/ + listener.requestReceived(); /*...and thus is known to implement + requestReceived() method*/ + } + +} + +class Dummy { + public void dummy() { + interface AnotherInterface extends Runnable { // local interface + void work (); + } + } + +} + +// Annotations ------------------- +@interface BlockingOperations { +} +@interface BlockingOperations { + boolean fileSystemOperations(); + boolean networkOperations() default false; +} +class Dummy { + @BlockingOperations(/*mandatory*/ fileSystemOperations = true, /*optional*/ + networkOperations = true) + void openOutputStream() { //Annotated method + } + + @Unused // Shorthand for @Unused() + void travelToJupiter() { + } + +} Added: plugins/Beauty/trunk/test/test_files/java/after/BlockTest.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/BlockTest.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/BlockTest.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,26 @@ +public class BlockTest { + int x; + + private void method1() { + int y; + } + + // a method + public int getC() { + x++; + switch (C) { + case 1: + return ++C; + case 2: + // do something + y = C + z; + break; + case 3: + + default: + return c; + } + return C; + } + +} Added: plugins/Beauty/trunk/test/test_files/java/after/Comments.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/Comments.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/Comments.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,54 @@ +// See http://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html +@Target({ElementType.TYPE, ElementType.TYPE_USE}) +public class LexerTest { + /** + * whatever is not a nice thing to say + * but it is what it is + */ + void whatever() { + if (x == 6) { + int y = 4; // because 4 is nice + + // but 14 is not nice + if (w == 14) { + z = 69; + } + } + else { + /* a comment */ + int w = 14; // and another + } + + if (x == 9) { + /* + * call doSim to do something + */ + doSim(); + } + + for ( String part : parts) { + doSomeStuff(); + andMore(); + break; + } + + for (int i = 0; i < 100; i++) { + i++; + } + while (true) { + System.out.println("+++++ it's true!"); + } + + do { + System.out.println("do it"); + } + while (true); + } + + class C0 { + } + + final class FC1 extends SC1 { + } + +} Added: plugins/Beauty/trunk/test/test_files/java/after/Comments2.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/Comments2.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/Comments2.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,37 @@ +// See http://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html +@Target({ElementType.TYPE, ElementType.TYPE_USE}) +public class LexerTest { + /** + * whatever is not a nice thing to say + * but it is what it is + */ + void whatever() { + if (y == 6) { + int z = 12; + } + } + + // a field + /* why */ private static final int C = 10; + + // a method + public int getC() { + return C; + } + + // a class + static class SC1 { + static final int C = 100; + + } + + // an enum + enum E1 { + ONE, TWO, THREE; + + Color() { + colorMap.put(toString(), this); + } + } + +} Added: plugins/Beauty/trunk/test/test_files/java/after/Element1.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/Element1.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/Element1.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,17 @@ +package com.whatever.enums.values; + +/** + * This is a simple enum of periodic table elements + */ +public enum Element1 { + H, + HE, + LI, + BE, + B, + C, + N, + O, + F, + NE +} Added: plugins/Beauty/trunk/test/test_files/java/after/EnumTest.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/EnumTest.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/EnumTest.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,31 @@ +import java.util.*; + + +enum Color { + RED, GREEN, BLUE; + + Color() { + colorMap.put(toString(), this); + } + + + static final Map<String, Color> colorMap = new HashMap<String, Color>(); + + + + static { + for ( Color c : Color.values()) { + colorMap.put(c.toString(), c); + } + } +} + +enum E1 { + ONE; + +} + +enum E { + provides; + +} Added: plugins/Beauty/trunk/test/test_files/java/after/IF_PERMITS.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/IF_PERMITS.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/IF_PERMITS.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,14 @@ +class IF_PERMITS { + final class T1 implements I1 { + } + + final class T2 implements I1 { + } + + interface I2 { + } + + sealed interface I1 extends I2 permits T1, T2 { + } + +} Added: plugins/Beauty/trunk/test/test_files/java/after/Ids.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/Ids.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/Ids.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,105 @@ +class Ids { + class oo { + class opens <T> { + enum E { + provides; + + } + + class provides <S> { + void f() { + opens<Byte>.provides<Long> b1 = new opens<>().new provides<>() { + }; + opens<Byte>.provides<Long> b2 = new opens().new provides() { + }; + } + + void g() { + E e = E.provides; + switch (e) { + case provides: + break; + } + } + + <T> Object var() { + return null; + } + + provides<Long> get() { + return null; + } + + class with <S> { + } + + static class SS <R> { + interface Sup <T> { + T get (); + } + + } + + void h() { + var o = get().<Long> var(); + SS.Sup<provides<Long>.with<Long>> s = @Issue1897.Dum1 provides<Long>.with<Long> :: new; + } + + class R { + <to> void f() { + } + + } + + } + + } + + } + + static class opens { + enum requires { + opens; + + } + + public static <T> void with(String s) { + } + + interface with { + default void f (){ + } + } + + class exports implements with { + void g() { + with.super.f(); + } + + } + + @interface to { + } + + class module { + public static <T> void with(String s) { + try { + } + catch ( Exception var) { + } + } + + } + + record provides(int to) { + void f() { + opens o = new opens(); + BiFunction<Long, Long, Long> b = (opens, with) -> 1L; + Consumer<String> c = opens.module :: <Byte> with; + } + + } + + } + +} Added: plugins/Beauty/trunk/test/test_files/java/after/ImportsAndAnnos.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/ImportsAndAnnos.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/ImportsAndAnnos.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,16 @@ +package var.var.sealed; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; + + +@interface Dummy { +} +@interface Dummy2 { +} +@Target({ElementType.TYPE, ElementType.TYPE_USE}) +@interface Dummy3 { +} Added: plugins/Beauty/trunk/test/test_files/java/after/ManyStringsConcat.java =================================================================== --- plugins/Beauty/trunk/test/test_files/java/after/ManyStringsConcat.java (rev 0) +++ plugins/Beauty/trunk/test/test_files/java/after/ManyStringsConcat.java 2022-10-02 03:25:43 UTC (rev 25610) @@ -0,0 +1,37 @@ +class Test { + @ApiModelProperty(value = + "x" + "x" + "x" + "x" + "x" + "x" + "x" + "x" + "x" + "x" + "x" + "x" + "x" + "x" + "x" ... [truncated message content] |
From: <dal...@us...> - 2022-10-02 03:23:14
|
Revision: 25609 http://sourceforge.net/p/jedit/svn/25609 Author: daleanson Date: 2022-10-02 03:23:12 +0000 (Sun, 02 Oct 2022) Log Message: ----------- split out tests from main build file Modified Paths: -------------- plugins/Beauty/trunk/build.xml Added Paths: ----------- plugins/Beauty/trunk/ant_java_test.xml Added: plugins/Beauty/trunk/ant_java_test.xml =================================================================== --- plugins/Beauty/trunk/ant_java_test.xml (rev 0) +++ plugins/Beauty/trunk/ant_java_test.xml 2022-10-02 03:23:12 UTC (rev 25609) @@ -0,0 +1,509 @@ +<project name="java_test" default="test" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless"> + <!-- ======================================================================== + Target: set classpath + ========================================================================= --> + <target name="setClasspath"> + <path id="classpathref"> + <!-- required locations/jars --> + <pathelement location="${classes.dir}" /> + <pathelement path="${java.class.path}"/> + + <!-- required for jEdit plugin --> + <pathelement location="${jedit.install.dir}/jedit.jar" /> + + <!-- dependencies --> + <pathelement location="${jedit.plugins.dir}/kappalayout.jar"/> + <pathelement location="${jedit.plugins.dir}/antlr-4.10.1-complete.jar"/> + </path> + </target> + + <!-- ======================================================================= + The tests use the default settings of JavaParserBeautyListener, that is, + softTabs = true + tabWidth = 4 + bracketStyle = ATTACHED + brokenBracket = false + breakElse = true + padParens = false + padOperators = true + blankLinesBeforePackage = 0 + blankLinesAfterPackage = 1 + blankLinesAfterImports = 2 + sortImports = true + groupImports = true + blankLinesBetweenImportGroups = 1 + blankLinesAfterClassBody = 1 + blankLinesBeforeMethods = 0 + blankLinesAfterMethods = 1 + sortModifiers = true + collapseMultipleBlankLinesTo = 1 + wrapLineLength = 120 + + NOTE: THESE TESTS EXEC THE SYSTEM DIFF!!! THEY WILL FAIL IF DIFF IS + NOT INSTALLED OR NOT ON THE PATH!!! + + TODO: change out the echos with a fail. + ======================================================================== --> + <target name="test" depends="IF_PERMITS,AllInOne11,AllInOne17,AllInOne8,BasicClass,BasicClass3,BlockTest,Comments, + Comments2,Element1,EnumTest,Ids,ImportsAndAnnos,ManyStringsConcat,module-info,outer,PatternMatching4instanceof, + PatternMatching4switchExp,Pizza,Records,SealedClasses,SwitchExpressions,TextBlocks,Yield"> + </target> + + <target name="Yield" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Yield.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Yield.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Yield.java" /> + </java> + <exec executable="diff" outputproperty="Yielddiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Yield.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Yield.java"/> + </exec> + <condition property="Yield" value="true"> + <equals arg1="${Yielddiff}" arg2=""/> + </condition> + <echo if:set="Yield">Yield passed</echo> + <echo unless:set="Yield">Yield failed: ${Yielddiff}</echo> + </target> + + <target name="TextBlocks" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/TextBlocks.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/TextBlocks.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/TextBlocks.java" /> + </java> + <exec executable="diff" outputproperty="TextBlocksdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/TextBlocks.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/TextBlocks.java"/> + </exec> + <condition property="TextBlocks" value="true"> + <equals arg1="${TextBlocksdiff}" arg2=""/> + </condition> + <echo if:set="TextBlocks">TextBlocks passed</echo> + <echo unless:set="TextBlocks">TextBlocks failed: ${TextBlocksdiff}</echo> + </target> + + <target name="SwitchExpressions" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/SwitchExpressions.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/SwitchExpressions.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/SwitchExpressions.java" /> + </java> + <exec executable="diff" outputproperty="SwitchExpressionsdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/SwitchExpressions.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/SwitchExpressions.java"/> + </exec> + <condition property="SwitchExpressions" value="true"> + <equals arg1="${SwitchExpressionsdiff}" arg2=""/> + </condition> + <echo if:set="SwitchExpressions">SwitchExpressions passed</echo> + <echo unless:set="SwitchExpressions">SwitchExpressions failed: ${SwitchExpressionsdiff}</echo> + </target> + + <target name="SealedClasses" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/SealedClasses.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/SealedClasses.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/SealedClasses.java" /> + </java> + <exec executable="diff" outputproperty="SealedClassesdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/SealedClasses.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/SealedClasses.java"/> + </exec> + <condition property="SealedClasses" value="true"> + <equals arg1="${SealedClassesdiff}" arg2=""/> + </condition> + <echo if:set="SealedClasses">SealedClasses passed</echo> + <echo unless:set="SealedClasses">SealedClasses failed: ${SealedClassesdiff}</echo> + </target> + + <target name="Records" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Records.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Records.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Records.java" /> + </java> + <exec executable="diff" outputproperty="Recordsdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Records.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Records.java"/> + </exec> + <condition property="Records" value="true"> + <equals arg1="${Recordsdiff}" arg2=""/> + </condition> + <echo if:set="Records">Records passed</echo> + <echo unless:set="Records">Records failed: ${Recordsdiff}</echo> + </target> + + <target name="Pizza" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Pizza.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Pizza.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Pizza.java" /> + </java> + <exec executable="diff" outputproperty="Pizzadiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Pizza.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Pizza.java"/> + </exec> + <condition property="Pizza" value="true"> + <equals arg1="${Pizzadiff}" arg2=""/> + </condition> + <echo if:set="Pizza">Pizza passed</echo> + <echo unless:set="Pizza">Pizza failed: ${Pizzadiff}</echo> + </target> + + <target name="PatternMatching4switchExp" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/PatternMatching4switchExp.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/PatternMatching4switchExp.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/PatternMatching4switchExp.java" /> + </java> + <exec executable="diff" outputproperty="PatternMatching4switchExpdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/PatternMatching4switchExp.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/PatternMatching4switchExp.java"/> + </exec> + <condition property="PatternMatching4switchExp" value="true"> + <equals arg1="${PatternMatching4switchExpdiff}" arg2=""/> + </condition> + <echo if:set="PatternMatching4switchExp">PatternMatching4switchExp passed</echo> + <echo unless:set="PatternMatching4switchExp">PatternMatching4switchExp failed: ${PatternMatching4switchExpdiff}</echo> + </target> + + <target name="PatternMatching4instanceof" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/PatternMatching4instanceof.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/PatternMatching4instanceof.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/PatternMatching4instanceof.java" /> + </java> + <exec executable="diff" outputproperty="PatternMatching4instanceofdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/PatternMatching4instanceof.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/PatternMatching4instanceof.java"/> + </exec> + <condition property="PatternMatching4instanceof" value="true"> + <equals arg1="${PatternMatching4instanceofdiff}" arg2=""/> + </condition> + <echo if:set="PatternMatching4instanceof">PatternMatching4instanceof passed</echo> + <echo unless:set="PatternMatching4instanceof">PatternMatching4instanceof failed: ${PatternMatching4instanceofdiff}</echo> + </target> + + <target name="outer" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/outer.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/outer.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/outer.java" /> + </java> + <exec executable="diff" outputproperty="outerdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/outer.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/outer.java"/> + </exec> + <condition property="outer" value="true"> + <equals arg1="${outerdiff}" arg2=""/> + </condition> + <echo if:set="outer">outer passed</echo> + <echo unless:set="outer">outer failed: ${outerdiff}</echo> + </target> + + <target name="module-info" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/module-info.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/module-info.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/module-info.java" /> + </java> + <exec executable="diff" outputproperty="module-infodiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/module-info.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/module-info.java"/> + </exec> + <condition property="module-info" value="true"> + <equals arg1="${module-infodiff}" arg2=""/> + </condition> + <echo if:set="module-info">module-info passed</echo> + <echo unless:set="module-info">module-info failed: ${module-infodiff}</echo> + </target> + + <target name="ManyStringsConcat" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/ManyStringsConcat.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/ManyStringsConcat.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/ManyStringsConcat.java" /> + </java> + <exec executable="diff" outputproperty="ManyStringsConcatdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/ManyStringsConcat.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/ManyStringsConcat.java"/> + </exec> + <condition property="ManyStringsConcat" value="true"> + <equals arg1="${ManyStringsConcatdiff}" arg2=""/> + </condition> + <echo if:set="ManyStringsConcat">ManyStringsConcat passed</echo> + <echo unless:set="ManyStringsConcat">ManyStringsConcat failed: ${ManyStringsConcatdiff}</echo> + </target> + + <target name="ImportsAndAnnos" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/ImportsAndAnnos.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/ImportsAndAnnos.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/ImportsAndAnnos.java" /> + </java> + <exec executable="diff" outputproperty="ImportsAndAnnosdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/ImportsAndAnnos.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/ImportsAndAnnos.java"/> + </exec> + <condition property="ImportsAndAnnos" value="true"> + <equals arg1="${ImportsAndAnnosdiff}" arg2=""/> + </condition> + <echo if:set="ImportsAndAnnos">ImportsAndAnnos passed</echo> + <echo unless:set="ImportsAndAnnos">ImportsAndAnnos failed: ${ImportsAndAnnosdiff}</echo> + </target> + + <target name="Ids" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Ids.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Ids.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Ids.java" /> + </java> + <exec executable="diff" outputproperty="Idsdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Ids.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Ids.java"/> + </exec> + <condition property="Ids" value="true"> + <equals arg1="${Idsdiff}" arg2=""/> + </condition> + <echo if:set="Ids">Ids passed</echo> + <echo unless:set="Ids">Ids failed: ${Idsdiff}</echo> + </target> + + <target name="EnumTest" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/EnumTest.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/EnumTest.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/EnumTest.java" /> + </java> + <exec executable="diff" outputproperty="EnumTestdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/EnumTest.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/EnumTest.java"/> + </exec> + <condition property="EnumTest" value="true"> + <equals arg1="${EnumTestdiff}" arg2=""/> + </condition> + <echo if:set="EnumTest">EnumTest passed</echo> + <echo unless:set="EnumTest">EnumTest failed: ${EnumTestdiff}</echo> + </target> + + <target name="Element1" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Element1.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Element1.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Element1.java" /> + </java> + <exec executable="diff" outputproperty="Element1diff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Element1.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Element1.java"/> + </exec> + <condition property="Element1" value="true"> + <equals arg1="${Element1diff}" arg2=""/> + </condition> + <echo if:set="Element1">Element1 passed</echo> + <echo unless:set="Element1">Element1 failed: ${Element1diff}</echo> + </target> + + <target name="Comments2" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Comments2.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Comments2.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Comments2.java" /> + </java> + <exec executable="diff" outputproperty="Comments2diff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Comments2.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Comments2.java"/> + </exec> + <condition property="Comments2" value="true"> + <equals arg1="${Comments2diff}" arg2=""/> + </condition> + <echo if:set="Comments2">Comments2 passed</echo> + <echo unless:set="Comments2">Comments2 failed: ${Comments2diff}</echo> + </target> + + <target name="Comments" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Comments.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/Comments.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Comments.java" /> + </java> + <exec executable="diff" outputproperty="Commentsdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/Comments.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/Comments.java"/> + </exec> + <condition property="Comments" value="true"> + <equals arg1="${Commentsdiff}" arg2=""/> + </condition> + <echo if:set="Comments">Comments passed</echo> + <echo unless:set="Comments">Comments failed: ${Commentsdiff}</echo> + </target> + + <target name="BlockTest" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BlockTest.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BlockTest.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BlockTest.java" /> + </java> + <exec executable="diff" outputproperty="BlockTestdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BlockTest.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/BlockTest.java"/> + </exec> + <condition property="BlockTest" value="true"> + <equals arg1="${BlockTestdiff}" arg2=""/> + </condition> + <echo if:set="BlockTest">BlockTest passed</echo> + <echo unless:set="BlockTest">BlockTest failed: ${BlockTestdiff}</echo> + </target> + + <target name="IF_PERMITS" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/IF_PERMITS.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/IF_PERMITS.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/IF_PERMITS.java" /> + </java> + <exec executable="diff" outputproperty="diff"> + <arg value="-a"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/IF_PERMITS.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/IF_PERMITS.java"/> + </exec> + <condition property="IF_PERMITS" value="true"> + <equals arg1="${diff}" arg2=""/> + </condition> + <echo if:set="IF_PERMITS">IF_PERMITS passed</echo> + <echo unless:set="IF_PERMITS">IF_PERMITS failed: ${diff}</echo> + </target> + + <target name="AllInOne11" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne11.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne11.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne11.java" /> + </java> + <exec executable="diff" outputproperty="AllInOne11diff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne11.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/AllInOne11.java"/> + </exec> + <condition property="AllInOne11" value="true"> + <equals arg1="${AllInOne11diff}" arg2=""/> + </condition> + <echo if:set="AllInOne11">AllInOne11 passed</echo> + <echo unless:set="AllInOne11">AllInOne11 failed: ${AllInOne11diff}</echo> + </target> + + <target name="AllInOne17" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne17.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne17.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne17.java" /> + </java> + <exec executable="diff" outputproperty="AllInOne17diff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne17.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/AllInOne17.java"/> + </exec> + <condition property="AllInOne17" value="true"> + <equals arg1="${AllInOne17diff}" arg2=""/> + </condition> + <echo if:set="AllInOne17">AllInOne17 passed</echo> + <echo unless:set="AllInOne17">AllInOne17 failed: ${AllInOne17diff}</echo> + </target> + + <target name="AllInOne8" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne8.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne8.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne8.java" /> + </java> + <exec executable="diff" outputproperty="AllInOne8diff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/AllInOne8.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/AllInOne8.java"/> + </exec> + <condition property="AllInOne8" value="true"> + <equals arg1="${AllInOne8diff}" arg2=""/> + </condition> + <echo if:set="AllInOne8">AllInOne8 passed</echo> + <echo unless:set="AllInOne8">AllInOne8 failed: ${AllInOne8diff}</echo> + </target> + + <target name="BasicClass" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BasicClass.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BasicClass.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BasicClass.java" /> + </java> + <exec executable="diff" outputproperty="BasicClassdiff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BasicClass.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/BasicClass.java"/> + </exec> + <condition property="BasicClass" value="true"> + <equals arg1="${BasicClassdiff}" arg2=""/> + </condition> + <echo if:set="BasicClass">BasicClass passed</echo> + <echo unless:set="BasicClass">BasicClass failed: ${BasicClassdiff}</echo> + </target> + + <target name="BasicClass3" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BasicClass3.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/BasicClass3.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BasicClass3.java" /> + </java> + <exec executable="diff" outputproperty="BasicClass3diff"> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/after/BasicClass3.java"/> + <arg value="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/expected/BasicClass3.java"/> + </exec> + <condition property="BasicClass3" value="true"> + <equals arg1="${BasicClass3diff}" arg2=""/> + </condition> + <echo if:set="BasicClass3">BasicClass3 passed</echo> + <echo unless:set="BasicClass3">BasicClass3 failed: ${BasicClass3diff}</echo> + </target> + +</project> \ No newline at end of file Modified: plugins/Beauty/trunk/build.xml =================================================================== --- plugins/Beauty/trunk/build.xml 2022-09-30 01:44:46 UTC (rev 25608) +++ plugins/Beauty/trunk/build.xml 2022-10-02 03:23:12 UTC (rev 25609) @@ -1,4 +1,4 @@ -<project name="Beauty" default="dist" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless"> +<project name="Beauty" default="dist" basedir="."> <echo>${java.home}</echo> <!-- read build.props to override properties set below --> @@ -264,30 +264,16 @@ depends="setClasspath"> <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/BasicClass2.java"/> <!-- - <arg file="/home/danson/src/svnkit-1.8.5/src/src/svnkit-1.8.5/svnkit-test/src/main/java/org/tmatesoft/svn/core/test/PythonTests.java"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test_files/java/before/AllInOne7.java"/> --> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test files/BasicClass2.java"/> </java> </target> <target name="all" depends="javacc,dist"/> - <target name="test" depends="setClasspath"> - <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> - <classpath refid="classpathref"/> - <arg file="/home/danson/src/jedit/plugins/Beauty/test/test files/java/before/IF_PERMITS.java"/> - <redirector - input="/home/danson/src/jedit/plugins/Beauty/test/test files/java/before/IF_PERMITS.java" - output="/home/danson/src/jedit/plugins/Beauty/test/test files/java/after/IF_PERMITS.java" /> - </java> - <condition property="test01passed" value="true"> - <filesmatch file1="/home/danson/src/jedit/plugins/Beauty/test/test files/java/after/IF_PERMITS.java" - file2="/home/danson/src/jedit/plugins/Beauty/test/test files/java/expected/IF_PERMITS.java" /> - </condition> - <echo if:set="test01passed">test01 passed</echo> - <echo unless:set="test01passed">test01 failed - did you remember to turn off tracing?</echo> - + <target name="test"> + <ant antfile="ant_java_test.xml" /> </target> - </project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-09-30 01:44:49
|
Revision: 25608 http://sourceforge.net/p/jedit/svn/25608 Author: daleanson Date: 2022-09-30 01:44:46 +0000 (Fri, 30 Sep 2022) Log Message: ----------- Adjustment of text block handling. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-27 18:47:08 UTC (rev 25607) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-30 01:44:46 UTC (rev 25608) @@ -325,7 +325,7 @@ } body = removeBlankLines(body, BOTH); if (bracketStyle == BROKEN) { - body = "\n" + body; + body = '\n' + body; } String identifier = pop(); @@ -1697,7 +1697,10 @@ // <assoc=right> expression // bop=('=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' | '>>=' | '>>>=' | '<<=' | '%=') // expression - String expression2 = pop().trim(); + String expression2 = pop(); + if (!isTextBlock(expression2)) { + expression2 = expression2.trim(); + } String bop = pop().trim(); if (bop.equals("<") ) { String peek = stack.peek(); @@ -1721,8 +1724,11 @@ } } - String expression1 = pop().trim(); - expression1 = indent(expression1); + String expression1 = pop(); + if (!isTextBlock(expression1)) { + expression1 = expression1.trim(); + expression1 = indent(expression1); + } StringBuilder sb = new StringBuilder(); sb.append(expression1); sb.append(padOperator(bop)); @@ -2606,7 +2612,7 @@ StringBuilder sb = new StringBuilder(); sb.append(start); - if (lines > 1 && !expressionList.startsWith("\"\"\"")) { // don't worry about text blocks + if (lines > 1 && !isTextBlock(expressionList)) { // don't worry about text blocks sb.append(lp).append('\n'); expressionList = removeBlankLines(expressionList, BOTH); sb.append(indentAgain(expressionList)); @@ -2618,7 +2624,12 @@ rp = padParen(rp); } sb.append(lp); - sb.append(expressionList.trim()); + if (isTextBlock(expressionList)) { + sb.append(expressionList); + } + else { + sb.append(expressionList.trim()); + } sb.append(rp); } push(sb); @@ -3517,7 +3528,6 @@ private void formatTry(StatementContext ctx) { // TRY block (catchClause+ finallyBlock? | finallyBlock) // TRY resourceSpecification block catchClause* finallyBlock? - // TODO: check try with resources, parens seem to be off if (ctx.resourceSpecification() != null) { // second choice String finallyBlock = ctx.finallyBlock() == null ? "" : pop(); @@ -5346,6 +5356,10 @@ private boolean isEmpty(StringBuilder sb) { return sb == null ? true : sb.length() == 0; } + + private boolean isTextBlock(String s) { + return s.startsWith("\"\"\""); + } // puts a space before and after the given operator, but only if padOperators is true, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-09-27 18:47:11
|
Revision: 25607 http://sourceforge.net/p/jedit/svn/25607 Author: daleanson Date: 2022-09-27 18:47:08 +0000 (Tue, 27 Sep 2022) Log Message: ----------- Updated version number and dependencies. Modified Paths: -------------- plugins/Beauty/trunk/beauty.props Modified: plugins/Beauty/trunk/beauty.props =================================================================== --- plugins/Beauty/trunk/beauty.props 2022-09-27 18:46:59 UTC (rev 25606) +++ plugins/Beauty/trunk/beauty.props 2022-09-27 18:47:08 UTC (rev 25607) @@ -1,15 +1,14 @@ # # Plugin properties -# borrowed some of this from AStyle # plugin.beauty.BeautyPlugin.activate=defer plugin.beauty.BeautyPlugin.name=Beauty plugin.beauty.BeautyPlugin.author=Dale Anson -plugin.beauty.BeautyPlugin.version=1.0.01 +plugin.beauty.BeautyPlugin.version=1.1 plugin.beauty.BeautyPlugin.docs=docs/index.html -plugin.beauty.BeautyPlugin.depend.0=jdk 1.8 -plugin.beauty.BeautyPlugin.depend.1=jedit 05.04.00.00 +plugin.beauty.BeautyPlugin.depend.0=jdk 11 +plugin.beauty.BeautyPlugin.depend.1=jedit 05.06.00.00 plugin.beauty.BeautyPlugin.depend.2=plugin CommonControlsPlugin 1.7.4 plugin.beauty.BeautyPlugin.depend.3=plugin antlr.AntlrPlugin 4.10 plugin.beauty.BeautyPlugin.usePluginHome=true This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-09-27 18:47:01
|
Revision: 25606 http://sourceforge.net/p/jedit/svn/25606 Author: daleanson Date: 2022-09-27 18:46:59 +0000 (Tue, 27 Sep 2022) Log Message: ----------- Fixed the error listener so the plugin will display errors correctly. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/ErrorListener.java plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/ErrorListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/ErrorListener.java 2022-09-13 11:13:00 UTC (rev 25605) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/ErrorListener.java 2022-09-27 18:46:59 UTC (rev 25606) @@ -1,4 +1,3 @@ - package beauty.parsers.java.java; import beauty.parsers.ParserException; @@ -7,8 +6,8 @@ import org.antlr.v4.runtime.*; + public class ErrorListener extends BaseErrorListener { - private List<ParserException> errors = new ArrayList<ParserException>(); public List<ParserException> getErrors() { @@ -15,16 +14,37 @@ return errors; } - public <T extends Token> void syntaxError( Recognizer<T, ?> recognizer, T offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e ) { + @Override + public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { int length = 0; - if ( e != null && e.getOffendingToken() != null ) { + + if (e != null && e.getOffendingToken() != null) { int startOffset = e.getOffendingToken().getStartIndex(); int endOffset = e.getOffendingToken().getStopIndex(); length = endOffset - startOffset; } + ParserException pe = new ParserException(wrapLongLine(msg), line, charPositionInLine, length); + errors.add(pe); + } - ParserException pe = new ParserException( msg, line, charPositionInLine, length ); - errors.add( pe ); - } + /** + * Takes a long line as input, splits it into line of no more than <code>wrapLineLength</code>. + */ + private String wrapLongLine(String s) { + StringTokenizer st = new StringTokenizer(s, " "); + StringBuilder sb = new StringBuilder(s.length()); + sb.append('\n'); // it's a long line so start it on a new line + int lineLength = 0; + while (st.hasMoreTokens()) { + String token = st.nextToken(); + if (lineLength + token.length() > 80) { + sb.append('\n'); + lineLength = 0; + } + sb.append(token).append(' '); + lineLength += token.length(); + } + return sb.toString(); + } + } - Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-13 11:13:00 UTC (rev 25605) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-27 18:46:59 UTC (rev 25606) @@ -1,6 +1,7 @@ package beauty.parsers.java.java; +import beauty.parsers.ParserException; import org.antlr.v4.runtime.*; import org.antlr.v4.runtime.tree.*; @@ -25,7 +26,7 @@ Standard parent/child tree hierarchy. The leaf child will be a one liner. - */ +*/ public class JavaParserBeautyListener extends JavaParserBaseListener { @@ -67,7 +68,7 @@ private boolean groupImports = true; private int blankLinesBetweenImportGroups = 1; private int blankLinesAfterClassBody = 1; - private int blankLinesBeforeMethods = 1; + private int blankLinesBeforeMethods = 0; private int blankLinesAfterMethods = 1; private boolean sortModifiers = true; private int collapseMultipleBlankLinesTo = 1; @@ -129,6 +130,7 @@ public static void main (String[] args) { if (args == null) return; + ErrorListener errorListener = null; try { // set up the parser //long startTime = System.currentTimeMillis(); @@ -137,21 +139,20 @@ JavaLexer lexer = new JavaLexer( antlrInput ); CommonTokenStream tokens = new CommonTokenStream( lexer ); JavaParser javaParser = new JavaParser( tokens ); - javaParser.setTrace(true); + //javaParser.setTrace(true); + javaParser.removeErrorListeners(); + errorListener = new ErrorListener(); + javaParser.addErrorListener( errorListener ); + javaParser.setErrorHandler( new DefaultErrorStrategy() ); // parse and beautify the buffer contents JavaParserBeautyListener listener = new JavaParserBeautyListener(16 * 1024, tokens); - listener.setUseSoftTabs(true); - listener.setIndentWidth(4); - listener.setPadParens(true); - listener.setBracketStyle(BROKEN); - listener.setBreakElse(true); ParseTreeWalker walker = new ParseTreeWalker(); ParseTree tree = javaParser.compilationUnit(); walker.walk( listener, tree ); //System.out.println("----- final output -----"); - System.out.println(listener.getText()); + System.out.print(listener.getText()); //System.out.println("------------------------"); //long elapsed = System.currentTimeMillis() - startTime; //System.out.println("elapsed time: " + elapsed + " ms"); @@ -158,6 +159,15 @@ } catch (Exception e) { e.printStackTrace(); + if (errorListener != null) { + java.util.List<ParserException> errors = errorListener.getErrors(); + + if ( errors != null && errors.size() > 0 ) { + for (ParserException error : errors) { + System.out.println("+++++ error: " + error); + } + } + } } } @@ -715,7 +725,7 @@ modifiers = indent(modifiers); sb.append(modifiers); if (hasNewLine) { - sb.append('\n').append(memberDeclaration); + sb.append('\n').append(memberDeclaration); } else { sb.append(' ').append(trimFront(memberDeclaration)); @@ -823,7 +833,11 @@ StringBuilder classDecl = new StringBuilder(); classDecl.append(class_).append(' ').append(identifier).append(typeParameters).append(extendsType).append(implementsList).append(permitsList).append(' ').append(classBody); - push(classDecl); + String decl = classDecl.toString(); + decl = removeBlankLines(decl, BOTH); + decl = addBlankLines(decl, blankLinesAfterClassBody, END); + + push(decl); } /** @@ -920,6 +934,8 @@ if (ctx.moduleDeclaration() != null) { pop(); // EOF String moduleDeclaration = pop(); + moduleDeclaration = removeBlankLines(moduleDeclaration, BOTH); + moduleDeclaration = removeExcessWhitespace(moduleDeclaration); output.append(moduleDeclaration); } else { @@ -947,6 +963,7 @@ output.append(packageDeclaration); output.append(importDeclarations); output.append(typeDeclarations); + } // all done! } @@ -2220,7 +2237,7 @@ } } StringBuilder sb = new StringBuilder(); - if (!annotations.isEmpty()) { + if (!isEmpty(annotations)) { sb.append(annotations); } sb.append(typeTypeOrVoid).append(' ').append(identifier).append(' ').append(formalParameters); @@ -2227,7 +2244,7 @@ if (!brackets.isEmpty()) { sb.append(brackets).append(' '); } - if (!qualifiedNameList.isEmpty()) { + if (!isEmpty(qualifiedNameList)) { sb.append(qualifiedNameList); if (methodBody.length() > 1) { sb.append(' '); @@ -2263,7 +2280,10 @@ interface_ = indent(interface_); StringBuilder sb = new StringBuilder(); sb.append(interface_).append(' ').append(identifier).append(typeParameters).append(extends_).append(permits_).append(' ').append(interfaceBody); - push(sb); + String decl = sb.toString(); + decl = removeBlankLines(decl, BOTH); + decl = addBlankLines(decl, blankLinesAfterClassBody, END); + push(decl); } /** @@ -2441,7 +2461,7 @@ sb.append(modifiers).append(' '); } sb.append(typeType); - if (!annotations.isEmpty()) { + if (!isEmpty(annotations)) { sb.append(' ').append(annotations); } sb.append(ellipsis).append(' ').append(id); @@ -2772,7 +2792,6 @@ } else if (ctx.PROVIDES() != null) { // PROVIDES qualifiedName WITH qualifiedName ';' - moduleDirective.append("provides "); String qualifiedName2 = pop(); String with_ = pop(); // with keyword String qualifiedName = pop(); @@ -3175,7 +3194,7 @@ * resourceSpecification * : '(' resources ';'? ')' * ; - * Multiple resources are already on separate lines; + * Multiple resources are already on separate lines. */ @Override public void exitResourceSpecification(ResourceSpecificationContext ctx) { String rp = pop(); // ) @@ -3193,7 +3212,7 @@ --tabCount; sb.append(resources).append(semi); rp = indent(rp); - sb.append(rp); + sb.append(rp).append('\n'); } else { sb.append(resources.trim()); @@ -3362,8 +3381,8 @@ StringBuilder sb = new StringBuilder(); sb.append(indent(if_)).append(' ').append(parExpression).append(' '); - // require brackets on ifStatement unless the statement is just ";" - if (!ifStatement.startsWith("{") && !ifStatement.equals(";")) { + // require brackets on ifStatement even if the statement is just ";" + if (!ifStatement.startsWith("{")) { if (bracketStyle == BROKEN) { sb.append('\n').append(indent("{")).append('\n'); } @@ -3498,6 +3517,7 @@ private void formatTry(StatementContext ctx) { // TRY block (catchClause+ finallyBlock? | finallyBlock) // TRY resourceSpecification block catchClause* finallyBlock? + // TODO: check try with resources, parens seem to be off if (ctx.resourceSpecification() != null) { // second choice String finallyBlock = ctx.finallyBlock() == null ? "" : pop(); @@ -3815,7 +3835,6 @@ String lb = pop(); // { if (bracketStyle == BROKEN) { lb = new StringBuilder().append('\n').append(indent(lb)).toString(); - //switchLabeledRule = indentAgain(switchLabeledRule); } else { lb = lb.trim(); @@ -3955,7 +3974,6 @@ StringBuilder sb = new StringBuilder(); String q = pop().trim(); // ? - String annotation = ""; if (ctx.annotation() != null) { int size = ctx.annotation().size(); List<String> annos = reverse(size); @@ -4167,11 +4185,11 @@ // put it all together StringBuilder sb = new StringBuilder(); - if (!annotations.isEmpty()) { + if (!isEmpty(annotations)) { sb.append(annotations); } sb.append(type); - if (!endPart.isEmpty()) { + if (!isEmpty(endPart)) { sb.append(endPart); } push(sb); @@ -5108,7 +5126,7 @@ String lineComment = ""; for (int i = 0; i < modifiers.size(); i++) { String mod = modifiers.get(i); - if (mod.indexOf('\n') > -1 && mod.indexOf("//") > -1 && !mod.startsWith("@")) { + if (mod.indexOf('\n') > -1 && mod.trim().indexOf("//") == 0 && !mod.startsWith("@")) { String[] lines = mod.split("\n"); for (String line : lines) { if (line.indexOf("//") > -1) { @@ -5124,7 +5142,7 @@ if (sortModifiers) { Collections.sort(modifiers, modifierComparator); } - + // modifiers shouldn't be on multiple lines, but comments preceding the // modifier may already be attached and can have multiple lines. // Handle the multiple lines here. @@ -5137,6 +5155,8 @@ modifier = modifier.trim(); if (modifier.startsWith("@") && !singleLine) { modifier += '\n'; // NOPMD + sb.append(modifier); + continue; } sb.append(modifier); if (i < modifiers.size() - 1) { @@ -5161,12 +5181,17 @@ private String modifiers = "public protected private abstract static final synchronized native sealed non-sealed strictfp transient volatile"; public int compare(String a, String b) { - // the modifier may have comments attaches, remove them before comparing + // the modifier may have comments attached, remove them before comparing String a_ = removeComments(a); String b_ = removeComments(b); - // annotations may be included in the choices + // annotations may be included in the choices. Note that the order of annotations + // is not specified by the JLS, so I'm defaulting to assuming two annotatations are + // equal, which should leave them in the original order. + if (a_.startsWith("@") && b_.startsWith("@")) { + return 0; + } if (a_.startsWith("@")) { return -1; } @@ -5316,6 +5341,12 @@ } return sb.toString(); } + + // Because StringBuilder doesn't get it's own isEmpty until Java 15 + private boolean isEmpty(StringBuilder sb) { + return sb == null ? true : sb.length() == 0; + } + // puts a space before and after the given operator, but only if padOperators is true, // otherwise, trims the given string and returns it. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2022-09-13 11:13:03
|
Revision: 25605 http://sourceforge.net/p/jedit/svn/25605 Author: kpouer Date: 2022-09-13 11:13:00 +0000 (Tue, 13 Sep 2022) Log Message: ----------- some cleanup Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/browser/VFSFileChooserDialog.java Modified: jEdit/trunk/org/gjt/sp/jedit/browser/VFSFileChooserDialog.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/browser/VFSFileChooserDialog.java 2022-09-13 11:01:01 UTC (rev 25604) +++ jEdit/trunk/org/gjt/sp/jedit/browser/VFSFileChooserDialog.java 2022-09-13 11:13:00 UTC (rev 25605) @@ -166,7 +166,6 @@ bufferDir,filename.substring(2)); } - int[] type = { -1 }; filename = MiscUtilities.expandVariables(filename); String path = MiscUtilities.constructPath(browser.getDirectory(),filename); VFS vfs = VFSManager.getVFSForPath(path); @@ -174,6 +173,7 @@ if(session == null) return; + int[] type = { -1 }; ThreadUtilities.runInBackground(new GetFileTypeRequest( vfs,session,path,type)); AwtRunnableQueue.INSTANCE.runAfterIoTasks(() -> @@ -262,7 +262,6 @@ private VFSFileNameField filenameField; private String filename; private JButton ok; - private JButton cancel; private boolean isOK; private TaskListener ioTaskHandler; //}}} @@ -282,12 +281,10 @@ return jEdit.getProperty("vfs.browser.title.open"); case VFSBrowser.SAVE_DIALOG: return jEdit.getProperty("vfs.browser.title.save"); + case VFSBrowser.BROWSER_DIALOG: + return jEdit.getProperty("vfs.browser.title.dialog"); case VFSBrowser.BROWSER: - return jEdit.getProperty("vfs.browser.title"); case VFSBrowser.CHOOSE_DIRECTORY_DIALOG: - return jEdit.getProperty("vfs.browser.title"); - case VFSBrowser.BROWSER_DIALOG: - return jEdit.getProperty("vfs.browser.title.dialog"); default: return jEdit.getProperty("vfs.browser.title"); } @@ -371,7 +368,7 @@ } ok.addActionListener(e -> ok()); - cancel = new JButton(jEdit.getProperty("common.cancel")); + JButton cancel = new JButton(jEdit.getProperty("common.cancel")); cancel.setName("cancel"); cancel.addActionListener(e -> cancel()); GenericGUIUtilities.makeSameSize(ok, cancel); @@ -413,8 +410,8 @@ @Nonnull private String[] getSelectedFiles(int type1, int type2) { - List<String> l = new ArrayList<>(); VFSFile[] selectedFiles = browser.getSelectedFiles(); + List<String> l = new ArrayList<>(selectedFiles.length); for (VFSFile file : selectedFiles) { if (file.getType() == type1 || file.getType() == type2) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2022-09-13 11:01:03
|
Revision: 25604 http://sourceforge.net/p/jedit/svn/25604 Author: kpouer Date: 2022-09-13 11:01:01 +0000 (Tue, 13 Sep 2022) Log Message: ----------- use of Math.min for simplification and reduce scope of some local variables Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/search/BoyerMooreSearchMatcher.java jEdit/trunk/org/gjt/sp/jedit/textarea/Gutter.java jEdit/trunk/org/gjt/sp/jedit/textarea/InputMethodSupport.java Modified: jEdit/trunk/org/gjt/sp/jedit/search/BoyerMooreSearchMatcher.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/search/BoyerMooreSearchMatcher.java 2022-09-10 22:05:01 UTC (rev 25603) +++ jEdit/trunk/org/gjt/sp/jedit/search/BoyerMooreSearchMatcher.java 2022-09-13 11:01:01 UTC (rev 25604) @@ -87,10 +87,9 @@ int _end = returnValue.end; if (wholeWord) { - CharSequence subText; while (!isWholeWord(text, returnValue.start, returnValue.end)) { - subText = text.subSequence(returnValue.end, text.length()); + CharSequence subText = text.subSequence(returnValue.end, text.length()); Match match = nextMatch(subText, start, end, firstTime, reverse); // match == returnValue or null if (match == null) @@ -157,11 +156,6 @@ // ? offset + pattern.length - 1 // : length - pattern.length; - char ch; - - int bad_char; - int good_suffix; - // the search works by starting the anchor (first character // of the pattern) at the initial offset. as long as the // anchor is far enough from the enough of the text for the @@ -180,7 +174,7 @@ for (pos = pattern_end; pos >= 0; --pos) { - ch = text.charAt(pos + anchor); + char ch = text.charAt(pos + anchor); if(ignoreCase) ch = Character.toUpperCase(ch); @@ -191,14 +185,14 @@ // character mismatch, determine how many characters to skip // heuristic #1 - bad_char = pos - skip[getSkipIndex(ch)]; + int bad_char = pos - skip[getSkipIndex(ch)]; // heuristic #2 - good_suffix = suffix[pos]; + int good_suffix = suffix[pos]; // skip the greater of the two distances provided by the // heuristics - int skip_index = (bad_char > good_suffix) ? bad_char : good_suffix; + int skip_index = Math.max(bad_char, good_suffix); anchor += skip_index; // go back to the while loop Modified: jEdit/trunk/org/gjt/sp/jedit/textarea/Gutter.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/textarea/Gutter.java 2022-09-10 22:05:01 UTC (rev 25603) +++ jEdit/trunk/org/gjt/sp/jedit/textarea/Gutter.java 2022-09-13 11:01:01 UTC (rev 25604) @@ -357,7 +357,7 @@ int digits; for (digits = 0; count > 0; digits++) count /= 10; - return (digits < minDigits) ? minDigits : digits; + return Math.max(digits, minDigits); } //}}} //{{{ setBuffer() method Modified: jEdit/trunk/org/gjt/sp/jedit/textarea/InputMethodSupport.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/textarea/InputMethodSupport.java 2022-09-10 22:05:01 UTC (rev 25603) +++ jEdit/trunk/org/gjt/sp/jedit/textarea/InputMethodSupport.java 2022-09-13 11:01:01 UTC (rev 25604) @@ -298,11 +298,7 @@ : composedCaretX; int visible_x = insertion_x + composed_visible_x; int painter_width = owner.getPainter().getWidth(); - int adjustment = 0; - if(visible_x < 0) - { - adjustment = visible_x; - } + int adjustment = Math.min(visible_x, 0); if(visible_x >= painter_width) { adjustment = visible_x - (painter_width - 1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-09-10 22:05:22
|
Revision: 25603 http://sourceforge.net/p/jedit/svn/25603 Author: daleanson Date: 2022-09-10 22:05:01 +0000 (Sat, 10 Sep 2022) Log Message: ----------- Continuing fine tuning. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-09 19:55:23 UTC (rev 25602) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-10 22:05:01 UTC (rev 25603) @@ -532,7 +532,7 @@ String blockStatements = ""; if (ctx.blockStatement() != null && ctx.blockStatement().size() > 0) { int size = ctx.blockStatement().size(); - blockStatements = reverse(size, ""); + blockStatements = reverse(size, "\n"); blockStatements = removeBlankLines(blockStatements, BOTH); } String lb = pop().trim(); @@ -698,7 +698,7 @@ sb.append(static_).append(' '); block = block.trim(); } - sb.append(block); + sb.append(block).append('\n'); push(sb); return; } @@ -1573,41 +1573,41 @@ if (ctx.typeType() != null && ctx.RPAREN() != null && ctx.LPAREN() != null) { // '(' annotation* typeType ('&' typeType)* ')' expression String expression = pop().trim(); - String rp = pop(); // ) + String rp = pop().trim(); // ) + + // there will be at least one typeType String typeTypes = ""; - if (ctx.typeType().size() > 1) { - List<String> parts = new ArrayList<String>(); - for (int i = 0; i < ctx.typeType().size() - 1; i++) { - parts.add(pop()); // typeType - parts.add(pop()); // & - } - Collections.reverse(parts); - StringBuilder sb = new StringBuilder(); - for (String part : parts) { - sb.append(part).append(' '); - } - typeTypes = sb.toString(); - } - String typeType = pop(); + int size = ctx.typeType().size() + ctx.BITAND().size(); + List<String> parts = reverse(size); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < parts.size(); i++) { + String part = parts.get(i).trim(); + sb.append(part); + if (i < parts.size() - 1) { + sb.append(' '); + } + } + typeTypes = sb.toString(); + String annotations = ""; if (ctx.annotation() != null) { - int size = ctx.annotation().size(); - List<String> parts = reverse(size); - StringBuilder sb = new StringBuilder(); + size = ctx.annotation().size(); + parts = reverse(size); + sb = new StringBuilder(); for (String part : parts) { - sb.append(part).append(' '); + sb.append(part.trim()).append(' '); } annotations = sb.toString(); } - String lp = pop(); // ( - StringBuilder sb = new StringBuilder(); - sb.append(lp); - sb.append(annotations); - sb.append(typeType); - if (typeTypes.length() > 0) { - sb.append(' ').append(typeTypes); + String lp = pop().trim(); // ( + + // put it all together + sb = new StringBuilder(); + sb.append(padParen(lp)); + if (!annotations.isEmpty()) { + sb.append(annotations); } - sb.append(rp).append(' ').append(expression); + sb.append(typeTypes).append(padParen(rp)).append(' ').append(expression); push(sb); return; } @@ -1705,7 +1705,7 @@ } String expression1 = pop().trim(); - expression1 = removeBlankLines(expression1, BOTH); + expression1 = indent(expression1); StringBuilder sb = new StringBuilder(); sb.append(expression1); sb.append(padOperator(bop)); @@ -1938,7 +1938,7 @@ String decl = pop(); String typeParameters = pop(); String modifiers = ""; - if (ctx.interfaceMethodModifier() != null) { + if (ctx.interfaceMethodModifier() != null && ctx.interfaceMethodModifier().size() > 0) { int size = ctx.interfaceMethodModifier().size(); modifiers = formatModifiers(size).trim(); } @@ -2196,28 +2196,44 @@ * ; */ @Override public void exitInterfaceCommonBodyDeclaration(InterfaceCommonBodyDeclarationContext ctx) { - String methodBody = pop().trim(); + String methodBody = pop().trim(); // block or ; StringBuilder qualifiedNameList = new StringBuilder(); if (ctx.qualifiedNameList() != null) { - String list = pop(); - String throws_ = pop(); // throws keyword + String list = pop().trim(); + String throws_ = pop().trim(); // throws keyword qualifiedNameList.append(throws_).append(' ').append(list); } String brackets = ""; if (ctx.RBRACK() != null) { - int size = ctx.RBRACK().size(); - brackets = reverse(size * 2, ""); + int size = ctx.RBRACK().size() + ctx.LBRACK().size(); + brackets = reverse(size, ""); } - String formalParameters = pop(); - String identifier = pop(); - String typeTypeOrVoid = pop(); - String annotations = ""; - if (ctx.annotation() != null) { + String formalParameters = pop().trim(); + String identifier = pop().trim(); + String typeTypeOrVoid = pop().trim(); + StringBuilder annotations = new StringBuilder(); + if (ctx.annotation() != null && ctx.annotation().size() > 0) { int size = ctx.annotation().size(); - annotations = reverse(size, " "); + List<String> annos = reverse(size); + for (String anno : annos) { + annotations.append(anno.trim()).append(' '); + } } StringBuilder sb = new StringBuilder(); - sb.append(annotations).append(typeTypeOrVoid).append(' ').append(identifier).append(formalParameters).append(brackets).append(qualifiedNameList).append(methodBody); + if (!annotations.isEmpty()) { + sb.append(annotations); + } + sb.append(typeTypeOrVoid).append(' ').append(identifier).append(' ').append(formalParameters); + if (!brackets.isEmpty()) { + sb.append(brackets).append(' '); + } + if (!qualifiedNameList.isEmpty()) { + sb.append(qualifiedNameList); + if (methodBody.length() > 1) { + sb.append(' '); + } + } + sb.append(methodBody); push(sb); } @@ -2402,12 +2418,18 @@ String id = pop(); String ellipsis = pop(); // ... - String annotations = ""; - if (ctx.annotation() != null) { + StringBuilder annotations = new StringBuilder(); + if (ctx.annotation() != null && ctx.annotation().size() > 0) { int size = ctx.annotation().size(); - annotations = reverse(size, " "); + List<String> annos = reverse(size); + for (int i = 0; i < annos.size(); i++) { + annotations.append(annos.get(i).trim()); + if (i < annos.size() - 1) { + annotations.append(' '); + } + } } - String typeType = pop(); + String typeType = pop().trim(); String modifiers = ""; if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); @@ -2415,7 +2437,10 @@ } StringBuilder sb = new StringBuilder(); - sb.append(modifiers).append(' ').append(typeType); + if (!modifiers.isEmpty()) { + sb.append(modifiers).append(' '); + } + sb.append(typeType); if (!annotations.isEmpty()) { sb.append(' ').append(annotations); } @@ -3079,7 +3104,7 @@ if (!impl.isEmpty()) { sb.append(impl).append(' '); } - sb.append(recordBody); + sb.append(recordBody).append('\n'); push(sb); } @@ -3155,7 +3180,7 @@ @Override public void exitResourceSpecification(ResourceSpecificationContext ctx) { String rp = pop(); // ) String semi = ctx.SEMI() == null ? "" : pop(); - String resources = pop(); + String resources = pop().trim(); String lp = pop(); // ( StringBuilder sb = new StringBuilder(); @@ -3167,9 +3192,6 @@ resources = indent(resources); --tabCount; sb.append(resources).append(semi); - if (!semi.endsWith("\n")) { - sb.append('\n'); - } rp = indent(rp); sb.append(rp); } @@ -3303,7 +3325,7 @@ if (!colon.isEmpty() && !expression2.isEmpty()) { sb.append(padOperator(colon)).append(expression2); } - sb.append(semi); + sb.append(semi).append('\n'); push(sb); } @@ -3329,7 +3351,7 @@ elseStatement.append(indent("}")).append('\n'); } else { - elseStatement.append(es); + elseStatement.append(es).append('\n'); } } @@ -3480,29 +3502,42 @@ // second choice String finallyBlock = ctx.finallyBlock() == null ? "" : pop(); String catchClause = ""; - if (ctx.catchClause() != null) { + if (ctx.catchClause() != null && ctx.catchClause().size() > 0) { int size = ctx.catchClause().size(); catchClause = reverse(size, ""); + catchClause = removeBlankLines(catchClause, BOTH); } - String block = pop().trim(); - String spec = pop(); - String try_ = pop(); // try keyword + String block = pop(); + if (bracketStyle == ATTACHED) { + block = block.trim(); + } + String spec = pop().trim(); + String try_ = pop().trim(); // try keyword try_ = indent(try_); StringBuilder sb = new StringBuilder(); - sb.append(try_).append(' ').append(spec).append(block); - if (!block.endsWith("\n") && breakElse) { - sb.append('\n'); + sb.append(try_).append(' ').append(spec).append(' ').append(block); + if (!catchClause.isEmpty()) { + if (breakElse && !block.endsWith("\n")) { + sb.append('\n'); + } + sb.append(catchClause); + if (!catchClause.endsWith("\n")) { + sb.append('\n'); + } } - sb.append(catchClause); - if (!catchClause.endsWith("\n") && breakElse) { - sb.append('\n'); + if (!finallyBlock.isEmpty()) { + finallyBlock = removeBlankLines(finallyBlock, BOTH); + if (breakElse && !endsWith(sb, "\n")) { + sb.append('\n'); + } + sb.append(finallyBlock).append('\n'); } - sb.append(finallyBlock); String tryStatement = sb.toString(); tryStatement = removeBlankLines(tryStatement, BOTH); push(tryStatement); } else { + // first choice String catchClause = ""; String finallyBlock = ""; if (ctx.catchClause() != null) { @@ -3527,14 +3562,17 @@ if (breakElse && !block.endsWith("\n")) { sb.append('\n'); } - sb.append(catchClause).append('\n'); + sb.append(catchClause); + if (!catchClause.endsWith("\n")) { + sb.append('\n'); + } } if (!finallyBlock.isEmpty()) { finallyBlock = removeBlankLines(finallyBlock, BOTH); - if (breakElse) { + if (breakElse && !endsWith(sb, "\n")) { sb.append('\n'); } - sb.append(finallyBlock); + sb.append(finallyBlock).append('\n'); } push(sb); } @@ -3586,7 +3624,7 @@ // SYNCHRONIZED parExpression block String block = pop(); if (bracketStyle == BROKEN) { - block = new StringBuilder().append('\n').append(block).toString(); + block = new StringBuilder().append(block).toString(); } else { block = block.trim(); @@ -3619,7 +3657,7 @@ if (!expression.isEmpty()) { sb.append(' '); } - sb.append(expression).append(semi); + sb.append(expression).append(semi).append('\n'); push(sb); } @@ -3729,10 +3767,16 @@ if (blockStatements.trim().startsWith("{")) { // it's a block - blockStatements = blockStatements.trim(); + //blockStatements = blockStatements.trim(); switchLabels = trimEnd(switchLabels) + ' '; } - else if (!switchLabels.endsWith("\n")) { + else { + // it's several statements + ++tabCount; + blockStatements = indent(blockStatements); + --tabCount; + } + if (!switchLabels.endsWith("\n")) { switchLabels = switchLabels + '\n'; // NOPMD } @@ -3836,11 +3880,13 @@ String switchRuleOutcome = ""; if (ctx.switchRuleOutcome() != null) { switchRuleOutcome = pop(); - if (switchRuleOutcome.lines().count() > 1) { - switchRuleOutcome = '\n' + switchRuleOutcome; + if (switchRuleOutcome.lines().count() == 1) { + switchRuleOutcome = switchRuleOutcome.trim(); } else { - switchRuleOutcome = switchRuleOutcome.trim(); + ++tabCount; + switchRuleOutcome = '\n' + indent(switchRuleOutcome); + --tabCount; } } String operator = pop().trim(); // arrow or colon @@ -3851,7 +3897,10 @@ push(sb); } else { - String switchRuleOutcome = pop().trim(); + String switchRuleOutcome = pop(); + if (switchRuleOutcome.lines().count() == 1) { + switchRuleOutcome = switchRuleOutcome.trim(); + } String operator = pop().trim(); String default_ = pop().trim(); default_ = indent(default_); @@ -3886,6 +3935,7 @@ // then case 1, 2: doesn't actually have a statement following it push(""); } + // otherwise, block is already on the stack } @@ -4026,25 +4076,30 @@ @Override public void exitTypeParameter(TypeParameterContext ctx) { String extends_ = ""; if (ctx.EXTENDS() != null) { - String typeBound = pop(); - StringBuilder annotations = new StringBuilder(); + StringBuilder sb = new StringBuilder(); + String typeBound = pop().trim(); + sb.append(typeBound); while(stack.peek().startsWith("@")) { - annotations.insert(0, pop()).append(' '); + sb.insert(0, ' '); + sb.insert(0, pop().trim()); } - extends_ = pop(); // extends keyword - annotations.append(typeBound); - annotations.insert(0, ' '); - annotations.insert(0, extends_); - annotations.insert(0, ' '); - extends_ = annotations.toString(); + sb.insert(0, ' '); + extends_ = pop().trim(); // extends keyword + sb.insert(0, extends_); + sb.insert(0, ' '); + extends_ = sb.toString(); } String identifier = pop().trim(); - StringBuilder annotations = new StringBuilder(); + StringBuilder sb = new StringBuilder(); while(stack.peek().startsWith("@")) { - annotations.insert(0, pop().trim()).append(' '); + sb.insert(0, ' '); + sb.insert(0, pop().trim()); } - annotations.append(identifier).append(extends_); - push(annotations); + sb.append(identifier); + if (!extends_.isEmpty()) { + sb.append(extends_); + } + push(sb); } @@ -4078,6 +4133,7 @@ // get the brackets endPart.insert(0, pop()); // ] endPart.insert(0, pop()); // [ + endPart.insert(0, ' '); // any annotations? if (ctx.annotation() != null) { @@ -4086,8 +4142,9 @@ if (ann.indexOf('@') > -1) { // using indexOf to be able to check for altAnnotationQualifiedName // as well as regular annotation - endPart.append(pop().trim()).append(' '); // annotation - ++ annotationCount; + endPart.insert(0, pop().trim()); // annotation + endPart.insert(0, ' '); + ++annotationCount; } else { break; @@ -4096,7 +4153,9 @@ } } } - String type = pop(); // one of (classOrInterfaceType | primitiveType) + + String type = pop().trim(); // one of (classOrInterfaceType | primitiveType) + // handle the rest of the annotations, if any StringBuilder annotations = new StringBuilder(); if (ctx.annotation() != null) { @@ -4108,8 +4167,11 @@ // put it all together StringBuilder sb = new StringBuilder(); - sb.append(annotations).append(type); - if (endPart.length() > 0) { + if (!annotations.isEmpty()) { + sb.append(annotations); + } + sb.append(type); + if (!endPart.isEmpty()) { sb.append(endPart); } push(sb); @@ -4511,21 +4573,25 @@ * Pads parenthesis so "(" becomes "( " and ")" becomes " )". * @param paren The paren to pad * @param item The item immediately following or preceding the paren. + * @return a padded paren or a trimmed paren depending on the padParens setting */ private String padParen(String paren, String item) { if (paren == null || paren.isEmpty() || !padParens || item == null || item.isEmpty()) { return paren; } + paren = paren.trim(); StringBuilder sb = new StringBuilder(paren); - int index = sb.indexOf("("); - if (index > -1) { - sb.insert(index + 1, " "); - } - else { - index = sb.indexOf(")"); + if (padParens) { + int index = sb.indexOf("("); if (index > -1) { - sb.insert(index == 0 ? 0 : index - 1, " "); + sb.insert(index + 1, " "); } + else { + index = sb.indexOf(")"); + if (index > -1) { + sb.insert(index == 0 ? 0 : index - 1, " "); + } + } } return sb.toString(); } @@ -5251,7 +5317,8 @@ return sb.toString(); } - // puts a space before and after the given operator + // puts a space before and after the given operator, but only if padOperators is true, + // otherwise, trims the given string and returns it. private String padOperator(String operator) { operator = operator.trim(); if (padOperators) { @@ -5263,6 +5330,9 @@ } private int getMemberType(MemberDeclarationContext ctx) { + if (ctx == null) { + return 0; + } // just a bunch of 'if's here if (ctx.methodDeclaration() != null || ctx.genericMethodDeclaration() != null) { return METHOD; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-09-09 19:55:25
|
Revision: 25602 http://sourceforge.net/p/jedit/svn/25602 Author: daleanson Date: 2022-09-09 19:55:23 +0000 (Fri, 09 Sep 2022) Log Message: ----------- Added broken bracket handling for classes, constructors, methods, and annotation type declarations. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-09 17:53:52 UTC (rev 25601) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-09 19:55:23 UTC (rev 25602) @@ -14,6 +14,9 @@ Reference Java Language Specification 17 Edition, https://docs.oracle.com/javase/specs/jls/se17/html/index.html + This should work for Java 18 also, since the only change is confirming a preview feature in Java 17, + pattern matching for switch expressions and statements. + Notes about indenting: Parent sets the indent level on entry @@ -22,7 +25,6 @@ Standard parent/child tree hierarchy. The leaf child will be a one liner. - */ public class JavaParserBeautyListener extends JavaParserBaseListener { @@ -296,7 +298,7 @@ sb.append(rb).append('\n'); } else { - sb.append(lb.trim()).append('\n').append(indent(rb.trim())).append('\n'); + sb.append(lb).append('\n').append(indent(rb)).append('\n'); } push(sb); } @@ -309,8 +311,13 @@ @Override public void exitAnnotationTypeDeclaration(AnnotationTypeDeclarationContext ctx) { String body = pop(); if (bracketStyle == ATTACHED) { - body = body.trim(); + body = body.trim(); } + body = removeBlankLines(body, BOTH); + if (bracketStyle == BROKEN) { + body = "\n" + body; + } + String identifier = pop(); String interface_ = pop(); // interface keyword String at = pop(); // @ @@ -707,8 +714,12 @@ boolean hasNewLine = modifiers.endsWith("\n"); modifiers = indent(modifiers); sb.append(modifiers); - sb.append(hasNewLine ? '\n' : ' '); - sb.append(trimFront(memberDeclaration)); + if (hasNewLine) { + sb.append('\n').append(memberDeclaration); + } + else { + sb.append(' ').append(trimFront(memberDeclaration)); + } } else { sb.append(memberDeclaration); @@ -776,7 +787,13 @@ */ @Override public void exitClassDeclaration(ClassDeclarationContext ctx) { String classBody = pop(); + if (bracketStyle == ATTACHED) { + classBody = classBody.trim(); + } classBody = removeBlankLines(classBody, BOTH); + if (bracketStyle == BROKEN) { + classBody = "\n" + classBody; + } StringBuilder permitsList = new StringBuilder(); if (ctx.PERMITS() != null && ctx.typeList() != null) { String typeList = pop(); @@ -977,10 +994,7 @@ */ @Override public void exitConstructorDeclaration(ConstructorDeclarationContext ctx) { String block = pop(); - if (bracketStyle == BROKEN) { - block = new StringBuilder().append('\n').append(block).toString(); - } - else { + if (bracketStyle == ATTACHED) { block = block.trim(); } StringBuilder throwsList = new StringBuilder(); @@ -2574,7 +2588,15 @@ * ; */ @Override public void exitMethodDeclaration(MethodDeclarationContext ctx) { - String methodBody = pop().trim(); + String methodBody = pop(); + if (bracketStyle == ATTACHED) { + methodBody = methodBody.trim(); + } + methodBody = removeBlankLines(methodBody, BOTH); + if (bracketStyle == BROKEN) { + methodBody = "\n" + methodBody; + } + String throwsList = ""; if (ctx.THROWS() != null) { String qualifiedNameList = pop(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-09-09 17:53:54
|
Revision: 25601 http://sourceforge.net/p/jedit/svn/25601 Author: daleanson Date: 2022-09-09 17:53:52 +0000 (Fri, 09 Sep 2022) Log Message: ----------- Continuing fine tuning. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-03 21:48:35 UTC (rev 25600) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-09 17:53:52 UTC (rev 25601) @@ -143,6 +143,7 @@ listener.setIndentWidth(4); listener.setPadParens(true); listener.setBracketStyle(BROKEN); + listener.setBreakElse(true); ParseTreeWalker walker = new ParseTreeWalker(); ParseTree tree = javaParser.compilationUnit(); walker.walk( listener, tree ); @@ -532,6 +533,7 @@ // assemble the parts StringBuilder sb = new StringBuilder(); + if (brokenBracket) { sb.append('\n'); sb.append(indent(lb)); @@ -587,10 +589,7 @@ */ @Override public void exitCatchClause(CatchClauseContext ctx) { String block = pop(); - if (bracketStyle == BROKEN) { - block = new StringBuilder().append('\n').append(block).toString(); - } - else { + if (bracketStyle == ATTACHED) { block = block.trim(); } String rb = pop(); // ) @@ -638,8 +637,8 @@ if (ctx.classBodyDeclaration() != null) { int size = ctx.classBodyDeclaration().size(); classBodyDecl = reverse(size, ""); - classBodyDecl = removeBlankLines(classBodyDecl, START); } + String lbrace = pop().trim(); if (bracketStyle == BROKEN) { lbrace = new StringBuilder().append('\n').append(indent(lbrace)).toString(); @@ -735,11 +734,16 @@ decl = addBlankLines(decl, blankLinesAfterClassBody, END); break; case FIELD: + if (!decl.endsWith("\n")) { + decl = addBlankLines(decl, 1, END); + } + break; default: decl = addBlankLines(decl, 1, BOTH); break; } push(decl); + } } @@ -772,6 +776,7 @@ */ @Override public void exitClassDeclaration(ClassDeclarationContext ctx) { String classBody = pop(); + classBody = removeBlankLines(classBody, BOTH); StringBuilder permitsList = new StringBuilder(); if (ctx.PERMITS() != null && ctx.typeList() != null) { String typeList = pop(); @@ -837,7 +842,7 @@ if (size == 1) { // only 1 identifier and maybe 1 typeArgument String typeArguments = ""; - if (ctx.typeArguments() != null && ctx.typeArguments().size() > 0) { + if (ctx.typeArguments() != null && ctx.typeArguments().size() == 1) { typeArguments = pop(); } String identifier = pop(); @@ -896,6 +901,7 @@ */ @Override public void exitCompilationUnit(CompilationUnitContext ctx) { if (ctx.moduleDeclaration() != null) { + pop(); // EOF String moduleDeclaration = pop(); output.append(moduleDeclaration); } @@ -1123,7 +1129,6 @@ */ @Override public void exitElementValuePair(ElementValuePairContext ctx) { String value = pop(); - System.out.println("+++++ value>" + value + "<"); String equals = pop(); // equals String identifier = pop(); StringBuilder pair = new StringBuilder(); @@ -1752,10 +1757,7 @@ */ @Override public void exitFinallyBlock(FinallyBlockContext ctx) { String block = pop(); - if (bracketStyle == BROKEN) { - block = new StringBuilder().append('\n').append(block).toString(); - } - else { + if (bracketStyle == ATTACHED) { block = block.trim(); } String finally_ = pop(); // finally keyword @@ -1821,12 +1823,15 @@ String id = pop(); String typeType = pop(); String modifiers = ""; - if (ctx.variableModifier() != null) { + if (ctx.variableModifier() != null && ctx.variableModifier().size() > 0) { int size = ctx.variableModifier().size(); modifiers = formatModifiers(size, true).trim(); } StringBuilder sb = new StringBuilder(); - sb.append(modifiers).append(' ').append(typeType).append(' ').append(id); + if (!modifiers.isEmpty()) { + sb.append(modifiers).append(' '); + } + sb.append(typeType).append(' ').append(id); push(sb); } @@ -1838,7 +1843,7 @@ */ @Override public void exitFormalParameterList(FormalParameterListContext ctx) { // only care about the first choice here, the second choice is already on the stack - if (ctx.formalParameter() != null) { + if (ctx.formalParameter() != null && ctx.formalParameter().size() > 0) { String lastFormalParameter = ""; String comma = ""; if (ctx.lastFormalParameter() != null) { @@ -1873,7 +1878,7 @@ @Override public void exitFormalParameters(FormalParametersContext ctx) { StringBuilder sb = new StringBuilder(); String rp = pop().trim(); // ) - if (ctx.receiverParameter() != null && ctx.formalParameterList() != null) { + if (ctx.receiverParameter() != null && ctx.formalParameterList() != null ) { // second choice String formalParameterList = pop(); String comma = pop().trim(); @@ -1965,7 +1970,7 @@ else if (ctx.typeType() != null) { // second choice StringBuilder expression = new StringBuilder(); - if (ctx.expression() != null) { + if (ctx.expression() != null && ctx.expression().size() > 0) { int size = ctx.expression().size(); List<String> parts = new ArrayList<String>(); for (int i = 0; i < size; i++) { @@ -2298,9 +2303,9 @@ * ; */ @Override public void exitLambdaExpression(LambdaExpressionContext ctx) { - String body = pop(); - String arrow = pop(); // -> - String params = pop(); + String body = pop().trim(); + String arrow = pop().trim(); // -> + String params = pop().trim(); StringBuilder sb = new StringBuilder(); sb.append(params).append(padOperator(arrow)).append(body); push(sb); @@ -2375,10 +2380,14 @@ * lastFormalParameter * : variableModifier* typeType annotation* '...' variableDeclaratorId * ; + * From JLS 17: In the grammar for VariableArityParameter, note that the ellipsis (...) is a + * token unto itself (§3.11). It is possible to put whitespace between it and the type, but this + * is discouraged as a matter of style. */ @Override public void exitLastFormalParameter(LastFormalParameterContext ctx) { String id = pop(); String ellipsis = pop(); // ... + String annotations = ""; if (ctx.annotation() != null) { int size = ctx.annotation().size(); @@ -2390,8 +2399,13 @@ int size = ctx.variableModifier().size(); modifiers = formatModifiers(size, true).trim(); } + StringBuilder sb = new StringBuilder(); - sb.append(modifiers).append(' ').append(typeType).append(' ').append(annotations).append(ellipsis).append(id); + sb.append(modifiers).append(' ').append(typeType); + if (!annotations.isEmpty()) { + sb.append(' ').append(annotations); + } + sb.append(ellipsis).append(' ').append(id); push(sb); } @@ -2458,6 +2472,7 @@ } else { String variableDecls = pop().trim(); + String typeType = pop(); typeType = indent(typeType); type.append(typeType).append(' ').append(variableDecls); @@ -2573,6 +2588,7 @@ } String formalParameters = pop().trim(); String identifier = pop().trim(); + String typeOrVoid = pop().trim(); typeOrVoid = indent(typeOrVoid); StringBuilder method = new StringBuilder(); @@ -2611,15 +2627,13 @@ --tabCount; String rbrace = pop(); rbrace = indent(rbrace); - StringBuilder moduleDirectives = new StringBuilder(); + String moduleDirectives = ""; if (ctx.moduleDirective() != null) { int size = ctx.moduleDirective().size(); - List<String> directives = reverse(size); - for (int i = 0; i < size; i++) { - moduleDirectives.append(directives.get(i)).append('\n'); - } + moduleDirectives = reverse(size, ""); + moduleDirectives = removeBlankLines(moduleDirectives, BOTH); } - String lbrace = indent(pop()); + String lbrace = pop().trim(); StringBuilder moduleBody = new StringBuilder(); moduleBody.append(lbrace).append('\n'); moduleBody.append(moduleDirectives); @@ -2933,15 +2947,21 @@ * ; */ @Override public void exitReceiverParameter(ReceiverParameterContext ctx) { - String this_ = pop(); // this keyword + String this_ = pop().trim(); // this keyword String identifiers = ""; if (ctx.identifier() != null) { int size = ctx.identifier().size(); identifiers = reverse(size * 2, ""); } - String typeType = pop(); + identifiers = identifiers.trim(); + StringBuilder sb = new StringBuilder(); - sb.append(typeType).append(identifiers).append(this_); + String typeType = pop().trim(); + sb.append(typeType).append(' '); + if (!identifiers.isEmpty()) { + sb.append(identifiers); + } + sb.append(this_); push(sb); } @@ -3239,7 +3259,8 @@ else if (ctx.COLON() != null) { formatColon(); } - // block is the only remaining choice, and it should already be on the stack + // block and expression are the only remaining choices, and should already be on the stack + } private void formatAssert(StatementContext ctx) { @@ -3314,10 +3335,10 @@ sb.append(ifStatement).append('\n'); } - sb.append(elseStatement); if (!endsWith(sb, "\n") && breakElse) { sb.append('\n'); } + sb.append(elseStatement); push(sb); } @@ -3391,7 +3412,7 @@ // DO statement WHILE parExpression ';' String semi = pop(); // ; String parExpression = pop(); - String while_ = indent(pop()); // while keyword + String while_ = pop().trim(); // while keyword String statement = pop().trim(); // always require brackets @@ -3416,7 +3437,17 @@ String do_ = pop(); // do keyword do_ = indent(do_); StringBuilder sb = new StringBuilder(); - sb.append(do_).append(' ').append(statement).append(' ').append(while_).append(' ').append(parExpression).append(semi); + sb.append(do_).append(' ').append(statement); + if (breakElse) { + if (!statement.endsWith("\n")) { + sb.append('\n'); + } + sb.append(indent(while_)); + } + else { + sb.append(' ').append(while_.trim()); + } + sb.append(' ').append(parExpression).append(semi); push(sb); } @@ -3437,11 +3468,11 @@ try_ = indent(try_); StringBuilder sb = new StringBuilder(); sb.append(try_).append(' ').append(spec).append(block); - if (!block.endsWith("\n")) { + if (!block.endsWith("\n") && breakElse) { sb.append('\n'); } sb.append(catchClause); - if (!catchClause.endsWith("\n")) { + if (!catchClause.endsWith("\n") && breakElse) { sb.append('\n'); } sb.append(finallyBlock); @@ -3456,15 +3487,13 @@ finallyBlock = ctx.finallyBlock() == null ? "" : pop(); int size = ctx.catchClause().size(); catchClause = reverse(size, ""); + catchClause = removeBlankLines(catchClause, BOTH); } else { finallyBlock = pop(); } String block = pop(); - if (bracketStyle == BROKEN) { - block = new StringBuilder().append('\n').append(block).toString(); - } - else { + if (bracketStyle == ATTACHED) { block = block.trim(); } @@ -3473,11 +3502,17 @@ StringBuilder sb = new StringBuilder(); sb.append(try_).append(' ').append(block); if (!catchClause.isEmpty()) { - sb.append('\n').append(catchClause); + if (breakElse && !block.endsWith("\n")) { + sb.append('\n'); + } + sb.append(catchClause).append('\n'); } if (!finallyBlock.isEmpty()) { finallyBlock = removeBlankLines(finallyBlock, BOTH); - sb.append('\n').append(finallyBlock); + if (breakElse) { + sb.append('\n'); + } + sb.append(finallyBlock); } push(sb); } @@ -3499,7 +3534,7 @@ } String lp = pop(); // { if (bracketStyle == BROKEN) { - lp = new StringBuilder().append('\n').append(lp).toString(); + lp = new StringBuilder().append('\n').append(indent(lp)).toString(); } else { lp = lp.trim(); @@ -3713,7 +3748,8 @@ } String lb = pop(); // { if (bracketStyle == BROKEN) { - lb = new StringBuilder().append('\n').append(lb).toString(); + lb = new StringBuilder().append('\n').append(indent(lb)).toString(); + //switchLabeledRule = indentAgain(switchLabeledRule); } else { lb = lb.trim(); @@ -3773,16 +3809,22 @@ * ; */ @Override public void exitSwitchLabeledRule(SwitchLabeledRuleContext ctx) { + StringBuilder sb = new StringBuilder(); if (ctx.CASE() != null) { String switchRuleOutcome = ""; if (ctx.switchRuleOutcome() != null) { - switchRuleOutcome = pop().trim(); + switchRuleOutcome = pop(); + if (switchRuleOutcome.lines().count() > 1) { + switchRuleOutcome = '\n' + switchRuleOutcome; + } + else { + switchRuleOutcome = switchRuleOutcome.trim(); + } } String operator = pop().trim(); // arrow or colon String choice = pop().trim(); // expressionList, null, or guardedPattern String case_ = pop().trim(); case_ = indent(case_); - StringBuilder sb = new StringBuilder(); sb.append(case_).append(' ').append(choice).append(padOperator(operator)).append(switchRuleOutcome).append('\n'); push(sb); } @@ -3791,7 +3833,6 @@ String operator = pop().trim(); String default_ = pop().trim(); default_ = indent(default_); - StringBuilder sb = new StringBuilder(); sb.append(default_).append(padOperator(operator)).append(switchRuleOutcome); push(sb); } @@ -3812,7 +3853,7 @@ int size = ctx.blockStatement().size(); blockStatement = reverse(size, " "); } - push(blockStatement.trim()); + push(blockStatement); } else if (ctx.block() == null) { // no block and no blockStatements, need a placeholder on the stack, @@ -3840,15 +3881,17 @@ typeType = pop() + " " + typeType; // NOPMD extends or super } + StringBuilder sb = new StringBuilder(); String q = pop().trim(); // ? String annotation = ""; if (ctx.annotation() != null) { int size = ctx.annotation().size(); - annotation = reverse(size, " "); + List<String> annos = reverse(size); + for (String a : annos) { + sb.append(a.trim()).append(' '); + } } - annotation = indent(annotation); - StringBuilder sb = new StringBuilder(); - sb.append(annotation).append(q).append(typeType); + sb.append(q).append(' ').append(typeType); push(sb); } } @@ -3860,12 +3903,23 @@ * ; */ @Override public void exitTypeArguments(TypeArgumentsContext ctx) { - String gt = pop(); // > - int size = ctx.typeArgument().size(); - String typeArguments = reverse(size * 2 - 1, " ", 2); - String lt = pop(); // < StringBuilder sb = new StringBuilder(); - sb.append(lt).append(typeArguments).append(gt); + + String gt = pop().trim(); // > + + int size = ctx.typeArgument().size() + ctx.COMMA().size(); + List<String> args = reverse(size); + for (int i = 0; i < args.size(); i++) { + String arg = args.get(i); + sb.append(arg.trim()); + if (arg.equals(",")) { + sb.append(' '); + } + } + + String lt = pop().trim(); // < + sb.insert(0, lt); + sb.append(gt); push(sb); } @@ -3962,10 +4016,10 @@ annotations.insert(0, ' '); extends_ = annotations.toString(); } - String identifier = pop(); + String identifier = pop().trim(); StringBuilder annotations = new StringBuilder(); while(stack.peek().startsWith("@")) { - annotations.insert(0, pop()).append(' '); + annotations.insert(0, pop().trim()).append(' '); } annotations.append(identifier).append(extends_); push(annotations); @@ -3978,10 +4032,10 @@ * ; */ @Override public void exitTypeParameters(TypeParametersContext ctx) { - String gt = pop(); // > + String gt = pop().trim(); // > int size = ctx.typeParameter().size(); String typeParameter = reverse(size * 2 - 1, " ", 2); - String lt = pop(); // < + String lt = pop().trim(); // < StringBuilder sb = new StringBuilder(); sb.append(lt).append(typeParameter).append(gt); push(sb); @@ -4060,7 +4114,7 @@ String equals = ""; if (ctx.variableInitializer() != null && ctx.ASSIGN() != null) { variableInitializer = pop().trim(); - if (variableInitializer.length() > wrapLineLength) { + if (variableInitializer.lines().count() == 1 && variableInitializer.length() > wrapLineLength) { variableInitializer = wrapLongLine(variableInitializer); variableInitializer = indent(variableInitializer); } @@ -5273,7 +5327,7 @@ sb.append('\n'); lineLength = 0; } - sb.append(token); + sb.append(token).append(' '); lineLength += token.length(); } return sb.toString(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-09-03 21:48:38
|
Revision: 25600 http://sourceforge.net/p/jedit/svn/25600 Author: daleanson Date: 2022-09-03 21:48:35 +0000 (Sat, 03 Sep 2022) Log Message: ----------- Adding test files. Added Paths: ----------- plugins/Beauty/trunk/test/test files/ plugins/Beauty/trunk/test/test files/1779.properties plugins/Beauty/trunk/test/test files/1779.props plugins/Beauty/trunk/test/test files/AllInOne11.java plugins/Beauty/trunk/test/test files/AllInOne17.java plugins/Beauty/trunk/test/test files/AllInOne7.java plugins/Beauty/trunk/test/test files/AllInOne8.java plugins/Beauty/trunk/test/test files/AnnotationTest.java plugins/Beauty/trunk/test/test files/BasicClass.java plugins/Beauty/trunk/test/test files/BasicClass2.java plugins/Beauty/trunk/test/test files/BasicClass3.java plugins/Beauty/trunk/test/test files/BlockTest.java plugins/Beauty/trunk/test/test files/Comments.java plugins/Beauty/trunk/test/test files/Comments2.java plugins/Beauty/trunk/test/test files/Element1.java plugins/Beauty/trunk/test/test files/EnumTest.java plugins/Beauty/trunk/test/test files/EnumTest2.java plugins/Beauty/trunk/test/test files/ManyStringsConcat.java plugins/Beauty/trunk/test/test files/ModuleTest.java plugins/Beauty/trunk/test/test files/Person.java plugins/Beauty/trunk/test/test files/Pizza.java plugins/Beauty/trunk/test/test files/SwitchTest.java plugins/Beauty/trunk/test/test files/java/ plugins/Beauty/trunk/test/test files/java/Ids.java plugins/Beauty/trunk/test/test files/java/ImportsAndAnnos.java plugins/Beauty/trunk/test/test files/java/PatternMatching4instancof.java plugins/Beauty/trunk/test/test files/java/PatternMatching4switchExp.java plugins/Beauty/trunk/test/test files/java/Records.java plugins/Beauty/trunk/test/test files/java/SealedClasses.java plugins/Beauty/trunk/test/test files/java/SwtichExpressions.java plugins/Beauty/trunk/test/test files/java/TextBlocks.java plugins/Beauty/trunk/test/test files/java/Yield.java plugins/Beauty/trunk/test/test files/java/after/ plugins/Beauty/trunk/test/test files/java/after/IF_PERMITS.java plugins/Beauty/trunk/test/test files/java/before/ plugins/Beauty/trunk/test/test files/java/before/IF_PERMITS.java plugins/Beauty/trunk/test/test files/java/expected/ plugins/Beauty/trunk/test/test files/java/expected/IF_PERMITS.java plugins/Beauty/trunk/test/test files/module-info.java plugins/Beauty/trunk/test/test files/outer.java Added: plugins/Beauty/trunk/test/test files/1779.properties =================================================================== --- plugins/Beauty/trunk/test/test files/1779.properties (rev 0) +++ plugins/Beauty/trunk/test/test files/1779.properties 2022-09-03 21:48:35 UTC (rev 25600) @@ -0,0 +1,41 @@ +plugin.sbtplugin.SbtPlugin.name=Simple Build Tool Plugin +plugin.sbtplugin.SbtPlugin.author=Marcelo Vanzin +plugin.sbtplugin.SbtPlugin.version=0.1.0 +plugin.sbtplugin.SbtPlugin.activate=defer +plugin.sbtplugin.SbtPlugin.usePluginHome=true +plugin.sbtplugin.SbtPlugin.description=Integration with the Scala Simple Build Tool. +plugin.sbtplugin.SbtPlugin.depend.0=jedit 05.00.99.00 +plugin.sbtplugin.SbtPlugin.depend.1=jdk 1.7 + +plugin.sbtplugin.SbtPlugin.depend.2=plugin CommonControlsPlugin 1.5 +plugin.sbtplugin.SbtPlugin.depend.3=plugin errorlist.ErrorListPlugin 2.1 +plugin.sbtplugin.SbtPlugin.depend.4=plugin console.ConsolePlugin 1.6 +plugin.sbtplugin.SbtPlugin.depend.5=plugin projectviewer.ProjectPlugin 3.5.3 + +sbtshell.title=SBT Shell +sbtshell.label=Open SBT Shell Dockable + +plugin.sbtplugin.SbtPlugin.menu.label=Project Viewer +projectviewer.menu=\ + projectviewer \ + projectviewer_focuswindow \ + projectviewer_parent-group \ + projectviewer_set-active \ + browse_project_root \ + - \ + projectviewer_wrapper_edit \ + projectviewer_wrapper_reimport \ + projectviewer_jarmaker_dialog \ + projectviewer_new-file \ + projectviewer_add-current-buffer \ + - \ + projectviewer_open_all_files \ + projectviewer_close_all_files \ + projectviewer_remove_all_files \ + projectviewer_wrapper_collapse_all \ + projectviewer_wrapper_expand_all \ + - \ + projectviewer_wrapper_search_project \ + projectviewer_wrapper_search \ + projectviewer_launch_current_buffer \ + projectviewer_paste_selected_files Property changes on: plugins/Beauty/trunk/test/test files/1779.properties ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: plugins/Beauty/trunk/test/test files/1779.props =================================================================== --- plugins/Beauty/trunk/test/test files/1779.props (rev 0) +++ plugins/Beauty/trunk/test/test files/1779.props 2022-09-03 21:48:35 UTC (rev 25600) @@ -0,0 +1,41 @@ +plugin.sbtplugin.SbtPlugin.name=Simple Build Tool Plugin +plugin.sbtplugin.SbtPlugin.author=Marcelo Vanzin +plugin.sbtplugin.SbtPlugin.version=0.1.0 +plugin.sbtplugin.SbtPlugin.activate=defer +plugin.sbtplugin.SbtPlugin.usePluginHome=true +plugin.sbtplugin.SbtPlugin.description=Integration with the Scala Simple Build Tool. +plugin.sbtplugin.SbtPlugin.depend.0=jedit 05.00.99.00 +plugin.sbtplugin.SbtPlugin.depend.1=jdk 1.7 + +plugin.sbtplugin.SbtPlugin.depend.2=plugin CommonControlsPlugin 1.5 +plugin.sbtplugin.SbtPlugin.depend.3=plugin errorlist.ErrorListPlugin 2.1 +plugin.sbtplugin.SbtPlugin.depend.4=plugin console.ConsolePlugin 1.6 +plugin.sbtplugin.SbtPlugin.depend.5=plugin projectviewer.ProjectPlugin 3.5.3 + +sbtshell.title=SBT Shell +sbtshell.label=Open SBT Shell Dockable + +plugin.sbtplugin.SbtPlugin.menu.label=Project Viewer +projectviewer.menu=\ + projectviewer \ + projectviewer_focuswindow \ + projectviewer_parent-group \ + projectviewer_set-active \ + browse_project_root \ + - \ + projectviewer_wrapper_edit \ + projectviewer_wrapper_reimport \ + projectviewer_jarmaker_dialog \ + projectviewer_new-file \ + projectviewer_add-current-buffer \ + - \ + projectviewer_open_all_files \ + projectviewer_close_all_files \ + projectviewer_remove_all_files \ + projectviewer_wrapper_collapse_all \ + projectviewer_wrapper_expand_all \ + - \ + projectviewer_wrapper_search_project \ + projectviewer_wrapper_search \ + projectviewer_launch_current_buffer \ + projectviewer_paste_selected_files Property changes on: plugins/Beauty/trunk/test/test files/1779.props ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: plugins/Beauty/trunk/test/test files/AllInOne11.java =================================================================== --- plugins/Beauty/trunk/test/test files/AllInOne11.java (rev 0) +++ plugins/Beauty/trunk/test/test files/AllInOne11.java 2022-09-03 21:48:35 UTC (rev 25600) @@ -0,0 +1,270 @@ +package var.var; + +import java.lang.annotation.*; +import java.util.ArrayList; +import java.util.List; + +import var.var.base.T; + +class Tests { + + class AC implements AutoCloseable { + + @Override + public void close() throws Exception { + + } + } + class TT extends var.var.base.T implements var.var.base.I { + + <T extends var.var.base.I> void f() { + } + + @Override + public void f1() { + + } + + void var() { + var: + for (; ; ) { + break var; + } + } + } + + interface II { + void var(); + } + + enum E1 { + var(1); + + E1(int i) { + + } + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.METHOD}) + public @interface TM1 { + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE}) + public @interface TM2 { + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.MODULE, ElementType.TYPE_USE}) + public @interface TM3 { + } + + static class PF { + protected int p; + static int sp; + static int var; + } + + static class CCC { + static int var = 0; + + static int var() { + return 0; + } + } + + { + final var c = 1; + PF.sp = c; + T t; + var var = 1; + var = var + var; + var b = (byte) var; + var r = var(); + var v = CCC.var; + var n = CCC.var() + CCC.var; + CI4 ci4 = new CI4(); + I4 i4a = ci4::var; + E1 e = E1.var; + switch (e) { + case var: + break; + } + } + + { + int var, i = 1; + } + + { + var var = new PF(); + var.var = 1; + } + + private int var = 1; + + int var() { + return 0; + } + + static { + final var c = 1; + PF.sp = c; + } + + { + var var = "var"; + var module = "module"; + var open = "open"; + var requires = "requires"; + var exports = "exports"; + var opens = "opens"; + var to = "to"; + var uses = "uses"; + var provides = "provides"; + var with = "with"; + var transitive = "transitive"; + } + + void foo() { + var f = 1; + } + + void foo2() throws Exception { + try (var a = new AC()) { + + for (final var i = 1; ; ) { + break; + } + + for (final var var = 1; ; ) { + break; + } + + List<Integer> lst = new ArrayList<>(); + for (final var item : lst) { + + } + + for (final var var : lst) { + + } + } + } + + void foo3() throws Exception { + var a = new AC(); + try (a) { + + } + } + + void foo31() throws Exception { + var var = new AC(); + var a = new AC(); + try (a; var) { + + } + } + + void foo4() { + + I1 i1a = (int i) -> 1; + I1 i1b = (var var) -> 1; + I1 i1c = var -> 1; + + I2 i2a = (final int var, int var1) -> 1; + I2 i2b = (final var var, var j) -> 1; + } + + interface I1 { + int m(int i); + } + + interface I2 { + int m2(int i, int j); + } + + interface I3 { + void m0(); + + default void m1() { + } + + private void m2() { + } + + private <T> void gm2(T t) { + } + + private static void m3() { + } + + static void m4() { + } + } + + interface I4 { + int var(); + } + + interface I6 { + default <TT,UU> void var() { + } + } + + class CI4 implements I4 { + + @Override + public int var() { + return 0; + } + } + + class CI6 implements I6 { + + public void vartest() { + I6.super.var(); + I6.super.<Byte, Long>var(); + } + } + + class D extends CI4 { + + public int var() { + return super.var(); + } + + void f(int var) { + + } + } + + static class Annos { + @interface InnerAnnotation { + int var() default 0; + } + + @interface OuterAnnotation { + InnerAnnotation var() default @InnerAnnotation(var = 1); + } + } + + static class TH{ + + void var(){} + int var = 1; + + TH(){ + this.var(); + this.var = 1; + System.out.println(var); + } + } + /* + */ +} Added: plugins/Beauty/trunk/test/test files/AllInOne17.java =================================================================== --- plugins/Beauty/trunk/test/test files/AllInOne17.java (rev 0) +++ plugins/Beauty/trunk/test/test files/AllInOne17.java 2022-09-03 21:48:35 UTC (rev 25600) @@ -0,0 +1,659 @@ +package var.var.sealed; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; + +@interface Dummy { +} + +@interface Dummy2 { +} + +@Target({ElementType.TYPE, ElementType.TYPE_USE}) + +@interface Dummy3 { +} + +/** + * https://openjdk.java.net/jeps/361 + */ +class SwitchExpressions { + + final static private int C = 10; + + static class SC1 { + final static int C = 100; + } + + enum E1 { + ONE; + } + + int fn1(int n) { + final int k = 4; + var r = switch (n) { + case 1, 2, 3 + 3, k, C, SC1.C -> 3 + SC1.C; + case 20 -> 3 + 4 + C - k; + case 21 -> { + int ff = 222; + yield ff; + } + case 22 -> { + yield 33 + 3; + } + case 99 -> { + throw new RuntimeException(""); + } + default -> 0; + }; + return r; + } + + String fn2(String s) { + return switch (s) { + //case null -> "n"; + case "a" -> ""; + case "b", "c" -> "a"; + default -> "o"; + }; + } + + int fn3(final int var) { + return switch (var) { + case 1 -> 2; + default -> var; + }; + } + + void fn4() { + + fn1(switch (1) { + case 1 -> 0; + case 2 -> 2; + default -> 1; + }); + } + + int fn5() { + E1 e = E1.ONE; + return switch (e) { + case ONE -> 0; + //default -> 1; + }; + } + + void fn6() { + switch (1) { + case 1 -> { + + } + } + } + + void fn7() { + switch (1) { + case 1 -> { + } + case 2 -> { + } + } + } + + void fn8() { + var i = 1; + switch (1) { + + } + var f = 2; + switch (2) { + case 2 -> { + f = 3; + } + } + } + + void fn9(String s) { + switch (s) { + case "" -> { + } + default -> { + } + } + } + + void fn10() { + var i = switch (1) { + case 1 -> switch (2) { + case 2 -> 0; + default -> 2; + }; + default -> 2; + }; + } + + void fn11() { + switch (1) { + case 1 -> throw new RuntimeException(""); + } + } + + int fn12() { + var v = 1; + int n = switch (1) { + case 1: + var g = 1; + System.out.println(); + yield v; + default: + yield 3; + }; + return n; + } + + void fn13() { + int n; + switch (1) { + case 1 -> n = 1; + } + } + + void fn14() { + switch (1) { + default -> { + } + } + + var n = 1; + var m = switch (n) { + case 1 -> 2; + case 2 -> 2; + default -> 1; + }; + + m = switch (n) { + case 2: + yield 2; + default: + yield 3; + }; + + + } +} + +/** + * https://openjdk.java.net/jeps/394 + */ +class PatternMatching4instanceof { + + void fn1(Number n) { + if (n instanceof Long var) { + var v = var; + } else if (n instanceof Integer open) { + var v = open; + } else if (n instanceof Byte) { + // + } else { + throw new RuntimeException(""); + } + + if (!(n instanceof Long l)) ; + + if (n instanceof final @Dummy @Dummy2 Long l && l.byteValue() == 1 + || n instanceof @Dummy @Dummy2 final Byte b && b.intValue() == 1) ; + + if (n instanceof Long) ; + if (n instanceof Long var) ; + if (n instanceof Long l) ; + if (n instanceof final Long l) ; + if (n instanceof @Dummy Long l) ; + if (n instanceof @Dummy @Dummy2 Long l) ; + if (n instanceof final @Dummy Long l) ; + if (n instanceof final @Dummy @Dummy2 Long l) ; + if (n instanceof @Dummy final Long l) ; + if (n instanceof @Dummy @Dummy2 final Long l) ; + } +} + +/** + * https://openjdk.java.net/jeps/406 + */ +class PatternMatching4switchExp { + + void f(int i) { + } + + void f1(Object obj) { + switch (obj) { + case null -> f(0); + case String s -> f(1); + case int[] a -> f(2); + default -> f(-1); + } + } + + void f2(Object obj) { + switch (obj) { + case null -> f(0); + case Long l -> f(1); + case Integer i -> f(1); + case int[] a -> f(2); + default -> f(-1); + } + } + + void f3(Object o) { + switch (o) { + case null: + case Long l: + f(0); + break; + default: + break; + } + } + + enum E1 { + var; + } + + void f4() { + var var = E1.var; + switch (var) { + case var: + return; + default: + break; + } + + switch (var) { + case var -> { + } + default -> { + } + } + } + + int f5(Number n) { + return switch (n) { + case Long l && l.intValue() == 1 && l.byteValue() == 1 -> l.byteValue(); + case Long var -> var.byteValue(); + case Integer i -> i.byteValue(); + default -> throw new RuntimeException(""); + }; + } + + Function<Integer, String> f6(Object obj) { + boolean b = true; + return switch (obj) { + case String var && b -> t -> var; + default -> t -> "Default string"; + }; + } + + int dummy() { + return 0; + } + + Function<Integer, String> f7(Object obj) { + boolean b = true; + boolean b2 = true; + boolean b3 = true; + return switch (obj) { + case (((String s) && (b && b2)) && s.length() > 0 && dummy() == 1) -> t -> s; + case (((Integer i && b && b2) && (b && b2)) && b3 && (b && b2)) -> t -> ""; + case (((Integer i && b && b2) && (b && b2)) && b3 && (b && b2 && !b3)) -> { + yield t -> ""; + } + case final Long l && (b ? b2 : b3) -> { + yield t -> ""; + } + default -> t -> "Default string"; + }; + } + + void f8(Object o, int i) { + switch (i) { + case 1, 2: + case 3, 4: { + } + } + + switch (o) { + case Number b: { + } + default: { + } + } + + var f = switch (o) { + case final I2 l: { + yield switch (o) { + case Byte b -> 1; + default -> 0; + }; + } + default: { + yield 1; + } + }; + } +} + +/** + * https://openjdk.java.net/jeps/395 + */ +class Records { + + interface I1 { + + } + + final record R1(@Dummy2 @Dummy int x) { + + R1(int x) { + this.x = x; + } + + enum E { + ONE; + + record ER() { + + } + } + + class C { + record CR() { + + } + } + + interface I { + record IR() { + + } + } + + final static private record R() implements I1 { + } + + final static protected record R2() implements I1 { + } + + final static public record R3() implements I1 { + } + + final static record R4() implements I1 { + } + } + + record R2() { + public @interface TM1 { + record AR() { + + } + } + } + + record R3<T>(int x, T y) { + } + + record R4<T>(int x, T y) implements I1 { + + } + + void fn1() { + final record Pt<T, G extends Number>(int x, int y) implements I1, R1.I { + void fn(T t) { + } + + <TT> void f() { + } + + //final int x; implicitly defined + + Pt(int x, int y) { + this.x = x; + this.y = y; + } + + //private int c = 1; not allowed + private final static int C = 1; //allowed + + static class C { + + } + } + + Pt<Long, Long> p = new Pt<>(1, 2); + p.fn(1L); + + + } + +} + +/** + * https://openjdk.java.net/jeps/378 + */ +class TextBlocks { + + void f(String s) { + } + + void fn() { + var s = """ + a \t + \r"""; + + var s2 = """ + a""" + """ + b"""; + + var s3 = """ + """; + + f(""" + a"""); + + f(""" + """); + } + +} + +/** + * https://openjdk.java.net/jeps/409 + */ +class SealedClasses { + + interface I1 { + } + + class C0 { + } + + sealed class SC1 extends C0 implements I1 permits FC1, FC2 { + + } + + sealed class SC2 { + void f() { + var non = 1; + var sealed = 2; + var ns = non - sealed; + var permits = 1; + var record = 1; + } + } + + final class FC1 extends SC1 { + + } + + final class FC2 extends SC1 { + + } + + non-sealed class NSC1 extends SC2 { + + } + + class C1 extends NSC1 { + + } +} + +class Ids { + class oo { + + class opens<T> { + + enum E { + provides; + } + + class provides<S> { + + void f() { + + opens<Byte>.provides<Long> b1 = new opens<>().new provides<>() { + }; + opens<Byte>.provides<Long> b2 = new opens().new provides() { + }; + } + + void g() { + E e = E.provides; + switch (e) { + case provides: + break; + } + } + + <T> Object var() { + return null; + } + + provides<Long> get() { + return null; + } + + class with<S> { + + } + + static class SS<R> { + interface Sup<T> { + T get(); + } + } + + void h() { + var o = get().<Long>var(); + + SS.Sup<provides<Long>.with<Long>> s = @Issue1897.Dum1 provides<Long>.with<Long>::new; + } + + class R { + + <to> void f() { + } + } + } + + + } + } + + static class opens { + enum requires { + opens; + + } + + public static <T> void with(String s) { + + } + + interface with { + default void f() { + } + } + + class exports implements with { + void g() { + with.super.f(); + } + } + + @interface to { + + } + + class module { + public static <T> void with(String s) { + try { + + } catch (Exception var) { + + } + } + } + + record provides(int to) { + + void f() { + + opens o = new opens(); + BiFunction<Long, Long, Long> b = (opens, with) -> 1L; + Consumer<String> c = opens.module::<Byte>with; + } + } + } + +} + +class Yield { + + int f(Object o) { + + final var yield = 1; + return switch (o) { + case Long l -> { + //var yield = 1; + yield yield; + } + default -> { + yield yield; + } + }; + } + + int yield(int yield){ + return yield; + } +} + + +class IF_PERMITS { + final class T1 implements I1 { + + } + + final class T2 implements I1 { + + } + + interface I2 { + } + + sealed interface I1 extends I2 permits T1, T2 { + + } + +} \ No newline at end of file Added: plugins/Beauty/trunk/test/test files/AllInOne7.java =================================================================== --- plugins/Beauty/trunk/test/test files/AllInOne7.java (rev 0) +++ plugins/Beauty/trunk/test/test files/AllInOne7.java 2022-09-03 21:48:35 UTC (rev 25600) @@ -0,0 +1,814 @@ + +// Source: https://en.wikipedia.org/wiki/Java_syntax +// Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html +/* This is a multi-line comment. + * It may occupy more than one line. */ +// This is an end-of-line comment + +/** + * This is a documentation comment. + * + * @author John Doe + */ +package myapplication.mylibrary; + + +import java.util.Random; // Single type declaration + +import java.*; +import static java.lang.System.out; //'out' is a static field in java.lang.System +import java.util.*; + +import static screen.ColorName.*; + + +public enum ColorName { + RED, BLUE, GREEN +}; + +// See http://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html +public class LexerTest { + static void main( String[] args ) { + long creditCardNumber = 1234_5678_9012_3456L; + + + long socialSecurityNumber = 999_99_9999L; + + + float pi = 3.14_15F; + + + long hexBytes = 0xFF_EC_DE_5E; + + + long hexWords = 0xCAFE_BABE; + + + long maxLong = 0x7fff_ffff_ffff_ffffL; + + + byte nybbles = 0b0010_0101; + + + long bytes = 0b11010010_01101001_10010100_10010010; + + + long lastReceivedMessageId = 0L; + + + double hexDouble1 = 0x1.0p0; + + + double hexDouble2 = 0x1.956ad0aae33a4p117; + + + int octal = 01234567; + + + long hexUpper = 0x1234567890ABCDEFL; + + + long hexLower = 0x1234567890abcedfl; + + + int x1 = _52; // This is an identifier, not a numeric literal + + + int x2 = 5_2; // OK (decimal literal) + + + int x4 = 5_______2; // OK (decimal literal) + + + int x7 = 0x5_2; // OK (hexadecimal literal) + + + int x9 = 0_52; // OK (octal literal) + + + int x10 = 05_2; // OK (octal literal) + + + int x, y, result; + // Arithmetic operators + result = x + y; + result = x - y; + result = x * y; + result = y / x; + result = x % 3; + // Unary operators + result = +x; + result = -y; + result = ++x; + result = --y; + + + boolean ok = false; + + + boolean not_ok = !ok; + // assignments yield a value + ( result = System.class ).getName(); + // Prefix & postfix + ++x; + x++; + --y; + y--; + LexerTest.prePost++; + LexerTest.prePost--; + myapplication.mylibrary.LexerTest.prePost++; + myapplication.mylibrary.LexerTest.prePost--; + this.prePost++; + this.prePost--; + super.prePost++; + super.prePost--; + someMethod()[0]++; + someMethod()[0]--; + ++LexerTest.prePost; + --LexerTest.prePost; + ++myapplication.mylibrary.LexerTest.prePost; + --myapplication.mylibrary.LexerTest.prePost; + ++this.prePost; + --this.prePost; + ++super.prePost; + --super.prePost; + ++someMethod()[0]; + --someMethod()[0]; + // Relational operators + result = x == y; + result = x != y; + result = x > y; + result = x >= y; + result = x < y; + result = x <= y; + + + // Conditional operators + if ( ( x > 8 ) && ( y > 8 ) ) { + } + + + if ( ( x > 10 ) || ( y > 10 ) ) { + } + result = ( x > 10 ) ? x : y; + + + // Ternary operator right associativity + int f = b1 ? b2 : b3 ? 3 : 4; + // Bitwise and Bit shift operators + result = ~x; + result = x << 1; + result = x >> 2; + result = x >>> 3; + result = x & 4; + result = x ^ 5; + result = x | 6; + // Assignment operators + result = x; + result += x; + result -= x; + result *= x; + result /= x; + result %= x; + result &= x; + result ^= x; + result |= x; + result <<= x; + result >>= x; + result >>>= x; + } + + public static void methodCalls() { + new Object().getClass().hashCode(); + new String[]{"test"}[0].getLength(); + + + String[] strings; + ( strings = new String[]{"test"} )[0].charAt( 0 ); + strings[0].length(); + + + Foo foo = new Foo().new Bar(); + foo.hashCode(); + Foo.class.hashCode(); + new HashMap<Object, String>( 5 ).get( null ); + } +} +public class ImportsTest { + public static void main( String[] args ) { + /* The following line is equivalent to + * java.util.Random random = new java.util.Random(); + * It would've been incorrect without the import declaration */ + Random random = new Random(); + } +} +public class HelloWorld { + public static void main( String[] args ) { + /* The following line is equivalent to: + * System.out.println("Hello World!"); + * and would have been incorrect without the import declaration. */ + out.println( "Hello World!" ); + + + // Conditional statements ------------------- + if ( i == 3 ) { + doSomething(); + } + + + if ( i == 2 ) { + doSomething(); + } + else { + doSomethingElse(); + } + + + if ( i == 3 ) { + doSomething(); + } + else if ( i == 2 ) { + doSomethingElse(); + } + else { + doSomethingDifferent(); + } + + + int a = 1; + + + int b = 2; + + + int minVal = ( a < b ) ? a : b; + // switch + switch ( ch ) { + case 'A': + doSomething(); // Triggered if ch == 'A' + break; + case 'B': + case 'C': + doSomethingElse(); // Triggered if ch == 'B' or ch == 'C' + break; + + + default: + doSomethingDifferent(); // Triggered in any other case + break; + } + // Iteration statements ------------------- + while ( i < 10 ) { + doSomething(); + } + + do { + doSomething(); + } while ( i < 10 ); + + for ( int i = 0; i < 10; i++ ) { + doSomething(); + } + + + // A more complex loop using two variables + for ( int i = 0, j = 9; i < 10; i++, j -= 3 ) { + doSomething(); + } + + + for ( ;; ) { + doSomething(); + } + + + for ( int i : intArray ) { + doSomething( i ); + } + + + // Jump statements ------------------- + // Label + start: + someMethod(); + + // break + for ( int i = 0; i < 10; i++ ) { + while ( true ) { + break; + } + // Will break to this point + } + + + outer: + for ( int i = 0; i < 10; i++ ) { + while ( true ) { + break outer; + } + } + + // Will break to this point + // continue + int ch; + while ( ch = getChar() ) { + if ( ch == ' ' ) { + continue; // Skips the rest of the while-loop + } + // Rest of the while-loop, will not be reached if ch == ' ' + doSomething(); + } + + outer: + for ( String str : stringsArr ) { + char[] strChars = str.toCharArray(); + + + for ( char ch : strChars ) { + if ( ch == ' ' ) { + /* Continues the outer cycle and the next + * string is retrieved from stringsArr */ + continue outer; + } + doSomething( ch ); + } + } + + // return + // If streamClosed is true, execution is stopped + if ( streamClosed ) { + return; + } + readFromStream(); + + + int result = a + b; + return result; // Exception handling statements ------------------- // try-catch-finally + try { + // Statements that may throw exceptions + methodThrowingExceptions(); + } + + catch ( Exception ex ) { + // Exception caught and handled here + reportException( ex ); + } + finally { + // Statements always executed after the try/catch blocks + freeResources(); + } try { + methodThrowingExceptions(); + } + + catch ( IOException | IllegalArgumentException ex ) { + // Both IOException and IllegalArgumentException will be caught and handled here + reportException( ex ); + } // try-with-resources statement try ( + FileOutputStream FileOutputStream = new FileOutputStream( "filename" ); + XMLEncoder XMLEncoder = new XMLEncoder( fos ) + + ){ + xEnc.writeObject( object ); + } + + catch ( IOException ex ) { + Logger.getLogger( Serializer.class.getName() ).log( Level.SEVERE, null, ex ); + } + + // throw + if ( obj == null ) { + // Throws exception of NullPointerException type + throw new NullPointerException(); + } + // Will not be called, if object is null + doSomethingWithObject( obj ); + // Thread concurrency control ------------------- + /* Acquires lock on someObject. It must be of a reference type and must be non-null */ + synchronized ( someObject ){ + // Synchronized statements + } + + + // assert statement + // If n equals 0, AssertionError is thrown + assert n != 0; + + /* If n equals 0, AssertionError will be thrown + * with the message after the colon */ + assert n != 0 : "n was equal to zero"; + + // Reference types ------------------- + // Arrays + int[] numbers = new int[5]; + numbers[0] = 2; + + + int x = numbers[0]; + + + // Initializers ------------------- + // Long syntax + int[] numbers = new int[]{20, 1, 42, 15, 34}; + + + // Short syntax + int[] numbers2 = {20, 1, 42, 15, 34}; + + + // Multi-dimensional arrays + int[][] numbers = new int[3][3]; + numbers[1][2] = 2; + + + int[][] numbers2 = {{2, 3, 2}, {1, 2, 6}, {2, 4, 5}}; + + + int[][] numbers = new int[2][]; //Initialization of the first dimension only + numbers[0] = new int[3]; + numbers[1] = new int[2]; + // Prefix & postfix + numbers[0][0]++; + numbers[0][0]--; + ++numbers[0][0]; + --numbers[0][0]; + foo()[0]++; + foo()[0]--; + ++foo()[0]; + --foo()[0]; + } +} + + +// Classes ------------------- +// Top-level class +class Foo { +// Class members +} + + +// Inner class +class Foo { // Top-level class + class Bar { // Inner class + } + + static void inner_class_constructor() { + // https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.9 + Foo foo = new Foo(); + + + Foo.Bar fooBar1 = foo.new Bar(); + + + Foo.Bar fooBar2 = new Foo().new Bar(); + } +} + + +// Nested class +class Foo { // Top-level class + static class Bar { // Nested class + } +} + + +// Local class +class Foo { + void bar() { + @WeakOuter class Foobar { // Local class within a method + } + } +} + + +// Anonymous class +class Foo { + void bar() { + new Object() { // Creation of a new anonymous class extending Object + }; + } +} +// Access modifiers +public class Foo { + int go() { + return 0; + } + + private class Bar { + } +} + + +// Constructors and initializers +class Foo { + String str; + + + Foo() { // Constructor with no arguments + // Initialization + } + + + Foo( String str ) { // Constructor with one argument + this.str = str; + } + +} + + +class Foo { + static { + // Initialization + } +} + + +class Foo { + { + // Initialization + } +} + + +// Methods ------------------- +class Foo { + public Foo() { + System.out.println( Foo.class.getName() + ": constructor runtime" ); + } + + + public Foo( int a, int b ) { + System.out.println( Foo.class.getName() + ": overloaded constructor " + this() ); + } + + + int bar( int a, int b ) { + return ( a * 2 ) + b; + } + + /* Overloaded method with the same name but different set of arguments */ + int bar( int a ) { + return a * 2; + } + + void openStream() throws IOException, myException { // Indicates that IOException may be thrown + } + + // Varargs + void printReport( String header, int ...numbers ) { //numbers represents varargs + System.out.println( header ); + + + for ( int num : numbers ) { + System.out.println( num ); + } + } +} + + +// Overriding methods +class Operation { + public int doSomething() { + return 0; + } +} + + +class NewOperation extends Operation { + @Override + public int doSomething() { + return 1; + } +} +// Abstract classes +public class AbstractClass { + private static final String hello; + + + + static { + System.out.println( AbstractClass.class.getName() + ": static block runtime" ); + hello = "hello from " + AbstractClass.class.getName(); + } { + System.out.println( AbstractClass.class.getName() + ": instance block runtime" ); + } + + public AbstractClass() { + System.out.println( AbstractClass.class.getName() + ": constructor runtime" ); + } + + + public static void hello() { + System.out.println( hello ); + } +} +public class CustomClass extends AbstractClass { + static { + System.out.println( CustomClass.class.getName() + ": static block runtime" ); + } { + System.out.println( CustomClass.class.getName() + ": instance block runtime" ); + } + + public CustomClass() { + super(); + System.out.println( CustomClass.class.getName() + ": constructor runtime" ); + } + + + public static void main( String[] args ) { + CustomClass nc = new CustomClass(); + hello(); + AbstractClass.hello(); //also valid + } +} + + +// Enumerations ------------------- +enum Season { + WINTER, SPRING, SUMMER, AUTUMN +} +public enum Season { + WINTER ( "Cold" ), SPRING ( "Warmer" ), SUMMER ( "Hot" ), AUTUMN ( "Cooler" ); + + Season( String description ) { + this.description = description; + } + + + private final String description; + + + + public String getDescription() { + return description; + } +} +public enum Season { + WINTER { + String getDescription() { + return "cold"; + } + }, + SPRING { + String getDescription() { + return "warmer"; + } + }, + SUMMER { + String getDescription() { + return "hot"; + } + }, + FALL { + String getDescription() { + return "cooler"; + } + }; + +} +// Interfaces ------------------- +interface ActionListener { + int ACTION_ADD = 0; + + int ACTION_REMOVE = 1; + + + void actionSelected( int action ); +} +interface RequestListener { + int requestReceived(); +} + + +class ActionHandler implements ActionListener, RequestListener { + public void actionSelected( int action ) { + } + + public int requestReceived() { + } +} + + +class Dummy { + public void dummy() { + // Calling method defined by interface + RequestListener listener = new ActionHandler(); /*ActionHandler can be + represented as RequestListener...*/ + listener.requestReceived(); /*...and thus is known to implement + requestReceived() method*/ + } +} + + +class Dummy { + public void dummy() { + interface AnotherInterface extends Runnable { // local interface + void work(); + } + } +} +// Annotations ------------------- +@interface BlockingOperations { +} +@interface BlockingOperations { + boolean fileSystemOperations(); + boolean networkOperations() default false; +} + + +class Dummy { + @BlockingOperations(/*mandatory*/ fileSystemOperations = true, /*optional*/networkOperations = true) +void openOutputStream() { //Annotated method + } + + @Unused // Shorthand for @Unused() +void travelToJupiter() { + } +} +// Generics ------------------- +// Generic classes +public class Mapper <T extends ArrayList & Formattable, V> { + public void add( T array, V item ) { + // array has add method because it is an ArrayList subclass + array.add( item ); + + + /* Mapper is created with CustomList as T and Integer as V. + * CustomList must be a subclass of ArrayList and implement Formattable */ + Mapper<CustomList, Integer> mapper = new Mapper<CustomList, Integer>(); + + + Mapper<CustomList, ?> mapper; + mapper = new Mapper<CustomList, Boolean>(); + mapper = new Mapper<CustomList, Integer>(); + } +} + + +// Generic methods and constructors ------------------- +class Mapper { + // The class itself is not generic, the constructor is + <T, V> Mapper( T array, V item ) { + } + + + /* This method will accept only arrays of the same type as + * the searched item type or its subtype*/ + static <T, V extends T> boolean contains( T item, V[] arr ) { + for ( T currentItem : arr ) { + if ( item.equals( currentItem ) ) { + return true; + } + } + return false; + } +} +interface Expandable <T extends Number> { + void addItem( T item ); +} + + +// This class is parameterized +class Array <T extends Number> implements Expandable<T> { + void addItem( T item ) { + } +} + + +// And this is not and uses an explicit type instead +class IntegerArray implements Expandable<Integer> { + void addItem( Integer item ) { + } +} +// Annotation type definition +public @interface Bean { + public staticfinalString ASDF = "ASDF"; +} + + +// Annotation alternative qualified name +class AnnoName <T> { + static <T> org.host.test.@N Bar<T> fn1( org.host.test.@N Bar<T> p ) { + return null; + } + + static <T> org.test.@N Bar<T> fn2( org.test.@N Bar<T> p ) { + return null; + } + + static <T> org.@N Bar<T> fn3( org.@N Bar<T> p ) { + return null; + } +} + + +// Instanceof +class InstanceOf { + public static void main( String[] args ) { + if ( args instanceof String[] ) { + } + + + if ( args instanceof a.String[] ) { + } + } +} Added: plugins/Beauty/trunk/test/test files/AllInOne8.java =================================================================== --- plugins/Beauty/trunk/test/test files/AllInOne8.java (rev 0) +++ plugins/Beauty/trunk/test/test files/AllInOne8.java 2022-09-03 21:48:35 UTC (rev 25600) @@ -0,0 +1,359 @@ +// Source: https://en.wikipedia.org/wiki/Java_syntax +// Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html + +// Lambdas +public class Lambdas { + public static void main(String[] args) { + // use predicate composition to remove matching names + List<Name> list = new ArrayList<>(); + for (Name name : NAMES) { + list.add(name); + } + Predicate<Name> pred1 = name -> "Sally".equals(name.firstName); + Predicate<Name> pred2 = name -> "Queue".equals(name.lastName); + list.removeIf(pred1.or(pred2)); + printNames("Names filtered by predicate:", list.toArray(new Name[list.size()])); + + Comparator<Name> com1 = Comparator.comparing((Name name1) -> name1.lastName) + .thenComparing(name2 -> name2.firstName); + Comparator<Name> com2 = Comparator.<Name,String>comparing(name1 -> name1.lastName) + .thenComparing(name2 -> name2.firstName); + + // sort array using lambda expression + copy = Arrays.copyOf(NAMES, NAMES.length); + Arrays.sort(copy, (a, b) -> a.compareTo(b)); + printNames("Names sorted with lambda expression:", copy); + } + +} + +class LambdaAndCastWithBounds{ + + interface I1<T> { + void fn(); + } + + interface I2 { + void fn(); + } + + I1<Byte> i1 = (I1<Byte> & Serializable & Cloneable) () -> { + }; + + I2 i2 = (I2 & Serializable & Cloneable) () -> { + }; + +} + +// Default interface method +interface Formula { + double calculate(int a); + + default double sqrt(int a) { + return Math.sqrt(a); + } +} + +// Double colon +public class For { + public void bar() { + Function<Computer, Integer> getAge = Computer::getAge; + Integer computerAge = getAge.apply(c1); + + Function<Computer, Integer> getAgeAlt = this::getAge; + Function<Computer, Integer> getAgeAlt2 = MyClass.this::getAge; + Function<Computer, Integer> getAgeAlt3 = generate()::getAge; + Function<Computer, Integer> getAgeAlt4 = MyClass.generate()::getAge; + Function<Computer, Integer> getAgeAlt5 = MyClass.twice().nested()::getAge; + Function<Computer, Integer> getAgeAlt6 = twice().nested()::getAge; + Function<Computer, Integer> getAgeAlt7 = this.singletonInstanceMethod::get; + + autodetect(this.beans, ((AutodetectCapableMBeanInfoAssembler) this.assembler)::includeBean); + + TriFunction <Integer, String, Integer, Computer> c6Function = Computer::new; + Computer c3 = c6Function.apply(2008, "black", 90); + + Function <Integer, Computer[]> computerCreator = Computer[]::new; + Computer[] computerArray = computerCreator.apply(5); + } + + // generic method printArray + public static < E > void printArray( E[] inputArray ) { + // Display array elements + for(E element : inputArray) { + System.out.printf("%s ", element); + } + System.out.println(); + } +} +/* +// Type Annotations +public class Annotations { + @Valid + private List<@NotNull String> property; +} +*/ +public interface CallableProcessingInterceptor { + default <T> void beforeConcurrentHandling(NativeWebRequest request, Callable<T> task) throws Exception { + } +} + +//@FunctionalInterface +public interface RouterFunction<T extends ServerResponse> { + default <S extends ServerResponse> RouterFunction<S> filter(HandlerFilterFunction<T, S> filterFunction) { + return new RouterFunctions.FilteredRouterFunction<>(this, filterFunction); + } +} + + +//Instanceof +class InstanceOf{ + public static void main(String[] args){ + if(args instanceof String[]){ + + } + if(args instanceof a.String[]){ + + } + } +} + +// Unicode +class Unicode { + public static void main(String[] args) { + System.out.println("A = \uuu0041"); + } +} + +// More Annotations +public class Annos { + + public Annos(int x, int y) throws IllegalArgumentException { + + } + + public @interface Dummy4 { + String[] value(); + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + public @interface Dummy03 { + Dummy3[] value(); + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + public @interface Dummy01 { + Dummy1[] value(); + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + @Repeatable(Dummy01.class) + public @interface Dummy1 { + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + public @interface Dummy2 { + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + @Repeatable(Dummy03.class) + public @interface Dummy3 { + } + + public static @Dummy4("#1") + @Dummy1 @Dummy3 <T extends @Dummy2 @Dummy3 Object> + @Dummy1 @Dummy3 T @Dummy1 @Dummy3 [] foo(@Dummy1 T @Dummy2 @Dummy3 [] arr, @Dummy1 @Dummy3 T @Dummy1 @Dummy3 ... t) { + return (@Dummy1 @Dummy3 T[]) null; + } + + public static @Dummy4("") + <@Dummy1 @Dummy2 T extends @Dummy1 @Dummy3 Object> + @Dummy1 @Dummy3 T @Dummy1 @Dummy3 [] @Dummy1 @Dummy2 [] foo2(@Dummy1 T @Dummy2 @Dummy3 [] @Dummy1 @Dummy3 [] arr) { + return (@Dummy1 @Dummy2 T[] @Dummy1 @Dummy2 []) null; + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.METHOD}) + public @interface TM1{ + } + + class Gen<T> { } + class A<@Dummy1 T extends @Dummy1 Gen<@Dummy1 T> >{} + + public static <@Dummy3 T> void foo3(T t, Gen<@Dummy1 @Dummy3 ? super @Dummy1 @Dummy3 T> c) { + } + + public static <@Dummy3 T> void foo33(T t, Gen<@Dummy1 @Dummy3 ? > c) { } + + public static <@Dummy3 T, @Dummy1 S> void foo333(T t, Gen<@Dummy1 @Dummy3 T @Dummy1 [] > c) { } + + public static @Dummy3 <@Dummy3 T extends @Dummy3 Gen<@Dummy1 ? super @Dummy1 T>> @Dummy3 T @Dummy3 [] f(@Dummy3 T @Dummy3 ... t) { + return (@Dummy3 T @Dummy3 []) null; + } + + interface TI1{ + public @TM1 void im01(); + public <@Dummy3 T> @TM1 @TM2 T gim01(@TM1 T t); + } + + static class Issue2454 { + interface I { + default <T> void fn1() { + } + + default <T, S, U> void fn2() { + } + } + + class C implements I { + + public void test() { + I.super.<Long>fn1(); // fix #2454 + I.super.fn1(); //ok + I.super.<List<Integer>, Byte, Map<Long, String>>fn2(); // fix #2454 + I.super.fn2(); //ok + } + } + } + +} + +public interface Electronic { + + // Constant variable + String LED = "LED"; + + // Abstract method + int getElectricityUse(); + + // Static method + static boolean isEnergyEfficient(String electtronicType) { + if (electtronicType.equals(LED)) { + return true; + } + return false; + } + + //Default method + default void printDescription() { + System.out.println("Electronic Description"); + } +} + +public enum Suit { + DIAMONDS (1, "Diamonds"), + CLUBS (2, "Clubs" ), + HEARTS (3, "Hearts" ), + SPADES (4, "Spades" ); + + private final int value; + private final String text; + Suit(int value, String text) { + this.value = value; + this.text = text; + } + public int value() {return value;} + public String text() {return text;} +} + +public enum Rank { + DEUCE (2 , "Two" ), + THREE (3 , "Three"), + FOUR (4 , "Four" ), + FIVE (5 , "Five" ), + SIX (6 , "Six" ), + SEVEN (7 , "Seven"), + EIGHT (8 , "Eight"), + NINE (9 , "Nine" ), + TEN (10, "Ten" ), + JACK (11, "Jack" ), + QUEEN (12, "Queen"), + KING (13, "King" ), + ACE (14, "Ace" ); + private final int value; + private final String text; + Rank(int value, String text) { + this.value = value; + this.text = text; + } + public int value() {return value;} + public String text() {return text;} +} + + + +class Issue1897 { + @Target({ElementType.TYPE, ElementType.TYPE_USE}) + @interface Dum1 { + } + + @Target(ElementType.TYPE_USE) + @interface Dum2 { + } + + @Target(ElementType.TYPE_USE) + @Retention(RetentionPolicy.RUNTIME) + @interface Dum3 { + } + + abstract class C { + // https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.1 + void f(@Dum1 @Dum2 C this) { + + } + + void d(C this, int i, int j) { + + } + + void e(C this, int i, int j, int... k) { + + } + + void c(C this, int... k) { + + } + + abstract void am(C this); + + class D { + + class E { + E(Issue1897.C.D D.this) { + } + } + + class GE { + <TY> GE(Issue1897.C.D D.this) { + + } + } + + void b(Issue1897.C.@Dum3 D Issue1897.C.D.this) { + + } + + void b2(Issue1897.C.@Dum3 D this) { + } + + void b3(@Dum1 D this) { + } + } + + void b(Issue1897.C Issue1897.C.this) { + + } + } +} +*/ Added: plugins/Beauty/trunk/test/test files/AnnotationTest.java =================================================================== --- plugins/Beauty/trunk/test/test files/AnnotationTest.java (rev 0) +++ plugins/Beauty/trunk/test/test files/AnnotationTest.java 2022-09-03 21:48:35 UTC (rev 25600) @@ -0,0 +1,4 @@ +public class Annotations implements IfA, IfB { + @Valid + private List<@NotNull String> property; +} Added: plugins/Beauty/trunk/test/test files/BasicClass.java =================================================================== --- plugins/Beauty/trunk/test/test files/BasicClass.java (rev 0) +++ plugins/Beauty/trunk/test/test files/BasicClass.java 2022-09-03 21:48:35 UTC (rev 25600) @@ -0,0 +1,50 @@ +package blah.var.foo; + +import java.util.*; + +import java.lang.annotation.ElementType; + +public class BasicClass { + // a field + final static /* why */ private int C = 10; + + // a method + public int getC() { + switch(C) { + case 1: + // what + return ++C; + case 2: + // do something + y = C + z; + break; + case 3: + default: + return c; + } + return C; + } + + // a class + static class SC1 { + final static int C = 100; + } + + // an enum + enum E1 { + ONE, TWO, THREE; + Color() { colorMap.put(toString(), this); } + } + + void fn4() { + // a switch expression + fn1( + switch (1) { + case 1 -> 0; + case 2 -> 2; + default -> 1; + }); + } + +} + Added: plugins/Beauty/trunk/test/test files/BasicClass2.java =================================================================== --- plugins/Beauty/trunk/test/test files/BasicClass2.java (rev 0) +++ plugins/Beauty/trunk/test/test files/BasicClass2.java 2022-09-03 21:48:35 UTC (rev 25600) @@ -0,0 +1,28 @@ +class Test { + public static void main( String[] args ) { + // Prefix & postfix + ++x; + if (x == 6) + --x; + + while (x == 6) + ++x; + + do + --x; + while(x == 9); + + for (;;) + ++x; + + if (x == 5) + ++z; + else if (x == 7) + --z; + + if (x == 9) + z = 9; + else + x = 2; + } +} Added: plugins/Beauty/trunk/test/test files/BasicClass3.java =================================================================== --- plugins/Beauty/trunk/test/test files/BasicClass3.java (rev 0) +++ plugins/Beauty/trunk/test/test files/BasicClass3.java 2022-09-03 21:48:35 UTC (rev 25600) @@ -0,0 +1,633 @@ +// Source: https://en.wikipedia.org/wiki/Java_syntax +// Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html + +/* This is a multi-line comment. +It may occupy more than one line. */ + +// This is an end-of-line comment + +/** + * This is a documentation comment. + * + * @author John Doe + */ + +package myapplication.mylibrary; + +import java.util.Random; // Single type declaration +import java.util.*; +import java.*; +import static java.lang.System.out; //'out' is a static field in java.lang.System +import static screen.ColorName.*; + +public enum ColorName { + RED, BLUE, GREEN +}; + +// See http://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html +public class LexerTest { + + static void main(String[] args) { + long creditCardNumber = 1234_5678_9012_3456L; + long socialSecurityNumber = 999_99_9999L; + float pi = 3.14_15F; + long hexBytes = 0xFF_EC_DE_5E; + long hexWords = 0xCAFE_BABE; + long maxLong = 0x7fff_ffff_ffff_ffffL; + byte nybbles = 0b0010_0101; + long bytes = 0b11010010_01101001_10010100_10010010; + long lastReceivedMessageId = 0L; + double hexDouble1 = 0x1.0p0; + double hexDouble2 = 0x1.956ad0aae33a4p117; + int octal = 01234567; + long hexUpper = 0x1234567890ABCDEFL; + long hexLower = 0x1234567890abcedfl; + + int x1 = _52; // This is an identifier, not a numeric literal + int x2 = 5_2; // OK (decimal literal) + int x4 = 5_______2; // OK (decimal literal) + + int x7 = 0x5_2; // OK (hexadecimal literal) + + int x9 = 0_52; // OK (octal literal) + int x10 = 05_2; // OK (octal literal) + + int x, y, result; + + // Arithmetic operators + result = x + y; + result = x - y; + result = x * y; + result = y / x; + result = x % 3; + + // Unary operators + result = +x; + result = -y; + result = ++x; + result = --y; + boolean ok = false; + boolean not_ok = !ok; + + // assignments yield a value + (result = System.class).getName(); + + // Prefix & postfix + ++x; + x++; + --y; + y--; + LexerTest.prePost++; + LexerTest.prePost--; + myapplication.mylibrary.LexerTest.prePost++; + myapplication.mylibrary.LexerTest.prePost--; + this.prePost++; + this.prePost--; + super.prePost++; + super.prePost--; + someMethod()[0]++; + someMethod()[0]--; + + ++LexerTest.prePost; + --LexerTest.prePost; + ++myapplication.mylibrary.LexerTest.prePost; + --myapplication.mylibrary.LexerTest.prePost; + ++this.prePost; + --this.prePost; + ++super.prePost; + --super.prePost; + ++someMethod()[0]; + --someMethod()[0]; + + // Relational operators + result = x == y; + result = x != y; + result = x > y; + result = x >= y; + result = x < y; + result = x <= y; + + // Conditional operators + if ((x > 8) && (y > 8)) { + } + + if ((x > 10) || (y > 10)) { + } + + result = (x > 10) ? x : y; + + // Ternary operator right associativity + int f = b1 ? b2 : b3 ? 3 : 4; + + // Bitwise and Bit shift operators + result = ~x; + result = x << 1; + + result = x >> 2; + result = x >>> 3; + result = x & 4; + result = x ^ 5; + result = x | 6; + + // Assignment operators + result = x; + result += x; + result -= x; + result... [truncated message content] |
From: <dal...@us...> - 2022-09-03 21:43:23
|
Revision: 25599 http://sourceforge.net/p/jedit/svn/25599 Author: daleanson Date: 2022-09-03 21:43:20 +0000 (Sat, 03 Sep 2022) Log Message: ----------- The java 17 beautifier appears to be complete. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java =================================================================== --- plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java 2022-09-02 21:24:47 UTC (rev 25598) +++ plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java 2022-09-03 21:43:20 UTC (rev 25599) @@ -16,25 +16,38 @@ import org.antlr.v4.runtime.tree.*; import org.gjt.sp.jedit.jEdit; -// This is a newer parser based on Antlr and supports java 17 language. +// This is a newer parser based on Antlr and supports java 17 language. public class Java17Beautifier extends Beautifier { + private int bracketStyle = 1; // JavaParser.ATTACHED; - private int bracketStyle = 1; // JavaParser.ATTACHED; private boolean breakElse = false; + private boolean padParens = false; + private boolean padOperators = false; + private int blankLinesBeforePackage = 0; + private int blankLinesAfterPackage = 1; + private int blankLinesAfterImports = 2; + private boolean sortImports = true; + private boolean groupImports = true; + private int blankLinesBetweenImportGroups = 1; - private int blankLinesAfterClassDeclaration = 1; + private int blankLinesAfterClassBody = 2; + private int blankLinesBeforeMethods = 1; + private int blankLinesAfterMethods = 1; + private boolean sortModifiers = true; + private int collapseMultipleBlankLinesTo = 1; + private int wrapLongLineLength = 120; public void init() { @@ -48,32 +61,35 @@ sortImports = jEdit.getBooleanProperty( "beauty.java8.sortImports", true ); groupImports = jEdit.getBooleanProperty( "beauty.java8.groupImports", true ); blankLinesBetweenImportGroups = jEdit.getIntegerProperty( "beauty.java8.blankLinesBetweenImportGroups", 1 ); - blankLinesAfterClassDeclaration = jEdit.getIntegerProperty( "beauty.java8.blankLinesAfterClassDeclaration", 1 ); blankLinesAfterClassBody = jEdit.getIntegerProperty( "beauty.java8.blankLinesAfterClassBody", 2 ); blankLinesBeforeMethods = jEdit.getIntegerProperty( "beauty.java8.blankLinesBeforeMethods", 1 ); blankLinesAfterMethods = jEdit.getIntegerProperty( "beauty.java8.blankLinesAfterMethods", 1 ); sortModifiers = jEdit.getBooleanProperty( "beauty.java8.sortModifiers", true ); collapseMultipleBlankLinesTo = jEdit.getIntegerProperty( "beauty.java8.collapseMultipleBlankLinesTo", 1 ); - wrapLongLineLength = jEdit.getIntegerProperty("beauty.java8.wrapLongLineLength", 120); + wrapLongLineLength = jEdit.getIntegerProperty( "beauty.java8.wrapLongLineLength", 120 ); } + public String beautify( String text ) throws ParserException { - ErrorListener errorListener = null; try { + // set up the parser + StringReader input = new StringReader( text ); + CharStream antlrInput = CharStreams.fromReader( input ); - // set up the parser - StringReader input = new StringReader( text ); - CharStream antlrInput = CharStreams.fromReader(input); JavaLexer lexer = new JavaLexer( antlrInput ); + CommonTokenStream tokens = new CommonTokenStream( lexer ); + JavaParser javaParser = new JavaParser( tokens ); + // for debugging String trace = System.getProperty( "beauty.java.trace" ); javaParser.setTrace( "true".equals( trace ) ); + // set up the formatting options JavaParserBeautyListener listener = new JavaParserBeautyListener( text.length() + 2048, tokens ); listener.setIndentWidth( getIndentWidth() ); @@ -88,14 +104,12 @@ listener.setSortImports( sortImports ); listener.setGroupImports( groupImports ); listener.setBlankLinesBetweenImportGroups( blankLinesBetweenImportGroups ); - listener.setBlankLinesAfterClassDeclaration( blankLinesAfterClassDeclaration ); listener.setBlankLinesAfterClassBody( blankLinesAfterClassBody ); listener.setBlankLinesBeforeMethods( blankLinesBeforeMethods ); listener.setBlankLinesAfterMethods( blankLinesAfterMethods ); listener.setSortModifiers( sortModifiers ); listener.setCollapseMultipleBlankLinesTo( collapseMultipleBlankLinesTo ); - listener.setWrapLongLineLength(wrapLongLineLength); - + listener.setWrapLongLineLength( wrapLongLineLength ); // add an error listener to the parser to capture any real errors javaParser.removeErrorListeners(); errorListener = new ErrorListener(); @@ -102,14 +116,18 @@ javaParser.addErrorListener( errorListener ); javaParser.setErrorHandler( new DefaultErrorStrategy() ); + // parse the buffer text ParseTreeWalker walker = new ParseTreeWalker(); + ParseTree tree = javaParser.compilationUnit(); walker.walk( listener, tree ); return listener.getText(); } - catch ( Exception e ) { - java.util.List <ParserException> errors = errorListener.getErrors(); + + catch ( Exception e ) { + java.util.List<ParserException> errors = errorListener.getErrors(); + if ( errors != null && errors.size() > 0 ) { throw errors.get( 0 ); } @@ -119,18 +137,19 @@ } } + public void setBracketStyle( int style ) { bracketStyle = style; } + public void setBreakElse( boolean b ) { breakElse = b; } + public void setPadParens( boolean pad ) { padParens = pad; } } - - Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-02 21:24:47 UTC (rev 25598) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-03 21:43:20 UTC (rev 25599) @@ -24,6 +24,7 @@ */ + public class JavaParserBeautyListener extends JavaParserBaseListener { // token stream, need this to capture comments @@ -63,9 +64,8 @@ private boolean sortImports = true; private boolean groupImports = true; private int blankLinesBetweenImportGroups = 1; - private int blankLinesAfterClassDeclaration = 1; private int blankLinesAfterClassBody = 1; - private int blankLinesBeforeMethods = 2; + private int blankLinesBeforeMethods = 1; private int blankLinesAfterMethods = 1; private boolean sortModifiers = true; private int collapseMultipleBlankLinesTo = 1; @@ -123,12 +123,13 @@ System.out.println("+++++ end stack " + name + " +++++"); } + // for testing public static void main (String[] args) { if (args == null) return; try { // set up the parser - long startTime = System.currentTimeMillis(); + //long startTime = System.currentTimeMillis(); java.io.FileReader input = new java.io.FileReader(args[0]); CharStream antlrInput = CharStreams.fromReader(input); JavaLexer lexer = new JavaLexer( antlrInput ); @@ -141,7 +142,7 @@ listener.setUseSoftTabs(true); listener.setIndentWidth(4); listener.setPadParens(true); - //listener.setBracketStyle(BROKEN); + listener.setBracketStyle(BROKEN); ParseTreeWalker walker = new ParseTreeWalker(); ParseTree tree = javaParser.compilationUnit(); walker.walk( listener, tree ); @@ -279,6 +280,10 @@ } } String lb = pop(); + if (bracketStyle == BROKEN) { + StringBuilder sb = new StringBuilder().append('\n').append(indent(lb)); + lb = sb.toString(); + } StringBuilder sb = new StringBuilder(); if (!isWhitespace(body)) { sb.append(lb); @@ -301,7 +306,10 @@ * ; */ @Override public void exitAnnotationTypeDeclaration(AnnotationTypeDeclarationContext ctx) { - String body = pop().trim(); + String body = pop(); + if (bracketStyle == ATTACHED) { + body = body.trim(); + } String identifier = pop(); String interface_ = pop(); // interface keyword String at = pop(); // @ @@ -544,7 +552,7 @@ if (!endsWith(sb, "\n")) { sb.append('\n'); } - sb.append(rb); + sb.append(rb).append('\n'); push(sb); } @@ -578,7 +586,13 @@ * ; */ @Override public void exitCatchClause(CatchClauseContext ctx) { - String block = pop().trim(); + String block = pop(); + if (bracketStyle == BROKEN) { + block = new StringBuilder().append('\n').append(block).toString(); + } + else { + block = block.trim(); + } String rb = pop(); // ) String identifier = pop(); String catchType = pop(); @@ -627,6 +641,12 @@ classBodyDecl = removeBlankLines(classBodyDecl, START); } String lbrace = pop().trim(); + if (bracketStyle == BROKEN) { + lbrace = new StringBuilder().append('\n').append(indent(lbrace)).toString(); + } + else { + lbrace = lbrace.trim(); + } StringBuilder sb = new StringBuilder(); if (brokenBracket) { @@ -702,19 +722,19 @@ MemberDeclarationContext mdc = ctx.memberDeclaration(); int type = getMemberType(mdc); switch(type) { - case FIELD: - decl = addBlankLines(decl, 1, END); - break; case CONSTRUCTOR: - decl = addBlankLines(decl, 1, START); - decl = addBlankLines(decl, 1, END); + case METHOD: + decl = addBlankLines(decl, blankLinesBeforeMethods, START); + decl = addBlankLines(decl, blankLinesAfterMethods, END); break; - case METHOD: - case INTERFACE: case ANNOTATION: case CLASS: case ENUM: + case INTERFACE: case RECORD: + decl = addBlankLines(decl, blankLinesAfterClassBody, END); + break; + case FIELD: default: decl = addBlankLines(decl, 1, BOTH); break; @@ -950,7 +970,13 @@ * ; */ @Override public void exitConstructorDeclaration(ConstructorDeclarationContext ctx) { - String block = pop().trim(); + String block = pop(); + if (bracketStyle == BROKEN) { + block = new StringBuilder().append('\n').append(block).toString(); + } + else { + block = block.trim(); + } StringBuilder throwsList = new StringBuilder(); if (ctx.THROWS() != null) { String qualifiedNameList = pop().trim(); @@ -1171,7 +1197,7 @@ StringBuilder sb = new StringBuilder(); sb.append(semi).append('\n'); if (!isWhitespace(classBodyDeclaration)) { - sb.append("\n"); + sb.append('\n'); sb.append(classBodyDeclaration); } push(sb); @@ -1264,6 +1290,12 @@ String comma = ctx.COMMA() == null ? "" : pop(); String enumConstants = ctx.enumConstants() == null ? "" : pop(); String lb = pop(); // { + if (bracketStyle == BROKEN) { + lb = new StringBuilder().append('\n').append(indent(lb)).toString(); + } + else { + lb = lb.trim(); + } String implements_ = ""; if (ctx.IMPLEMENTS() != null && ctx.typeList() != null) { String typeList = pop(); @@ -1593,11 +1625,11 @@ else { // it's one of the prefix expressions, and they are all the same String expression = pop().trim(); - String pre = pop(); - pre = removeBlankLines(pre, BOTH); + String pre = pop().trim(); StringBuilder sb = new StringBuilder(); sb.append(pre).append(expression); - push(sb); + pre = indent(sb.toString()); + push(pre); return; } @@ -1719,7 +1751,13 @@ * ; */ @Override public void exitFinallyBlock(FinallyBlockContext ctx) { - String block = pop().trim(); + String block = pop(); + if (bracketStyle == BROKEN) { + block = new StringBuilder().append('\n').append(block).toString(); + } + else { + block = block.trim(); + } String finally_ = pop(); // finally keyword finally_ = indent(finally_); push(finally_ + ' ' + block); @@ -2063,10 +2101,15 @@ } String lb = pop().trim(); // { - lb += '\n'; + if (bracketStyle == BROKEN) { + lb = new StringBuilder().append('\n').append(lb).append('\n').toString(); + } + else { + lb = lb.trim(); + } StringBuilder sb = new StringBuilder(); - sb.append(lb); + sb.append(lb).append('\n'); sb.append(body); trimEnd(sb); @@ -2107,14 +2150,18 @@ int type = getInterfaceMemberType(mdc); switch(type) { case CONST: - decl = addBlankLines(decl, 1, END); break; case METHOD: + decl = addBlankLines(decl, blankLinesBeforeMethods, START); + decl = addBlankLines(decl, blankLinesAfterMethods, END); + break; case INTERFACE: case ANNOTATION: case CLASS: case ENUM: case RECORD: + decl = addBlankLines(decl, blankLinesAfterClassBody, END); + break; default: decl = addBlankLines(decl, 1, BOTH); break; @@ -2572,9 +2619,9 @@ moduleDirectives.append(directives.get(i)).append('\n'); } } - String lbrace = pop() + '\n'; + String lbrace = indent(pop()); StringBuilder moduleBody = new StringBuilder(); - moduleBody.append(lbrace); + moduleBody.append(lbrace).append('\n'); moduleBody.append(moduleDirectives); moduleBody.append(rbrace); push(moduleBody); @@ -2919,6 +2966,12 @@ classBodyDeclaration = removeBlankLines(classBodyDeclaration, START); } String lb = pop().trim(); // { + if (bracketStyle == BROKEN) { + lb = new StringBuilder().append('\n').append(indent(lb)).toString(); + } + else { + lb = lb.trim(); + } StringBuilder sb = new StringBuilder(); sb.append(lb).append('\n'); if (!classBodyDeclaration.isEmpty()) { @@ -3037,7 +3090,7 @@ else { String id = pop().trim(); String type = pop().trim(); - middle = type + ' ' + type; + middle = type + ' ' + id; } String modifiers = ""; if (ctx.variableModifier() != null) { @@ -3153,13 +3206,13 @@ formatIf(ctx); } else if (ctx.FOR() != null) { - formatFor(ctx); + formatFor(); } else if (ctx.DO() != null && ctx.WHILE() != null) { - formatDo(ctx); + formatDo(); } else if (ctx.WHILE() != null) { - formatWhile(ctx); + formatWhile(); } else if (ctx.TRY() != null) { formatTry(ctx); @@ -3184,7 +3237,7 @@ formatSemi(ctx); } else if (ctx.COLON() != null) { - formatColon(ctx); + formatColon(); } // block is the only remaining choice, and it should already be on the stack } @@ -3217,13 +3270,18 @@ if (ctx.ELSE() != null) { String es = pop().trim(); String else_ = indent(pop().trim()); // else keyword - //elseStatement.append('\n'); elseStatement.append(else_).append(' '); // require brackets unless it's an "else if" statement if (!es.startsWith("{") && !es.startsWith("if")) { + if (bracketStyle == BROKEN) { + elseStatement.append('\n').append(indent("{")).append('\n'); + } + else { + elseStatement.append("{\n"); + } ++tabCount; - elseStatement.append("{\n").append(indent(es)).append('\n'); + elseStatement.append(indent(es)).append('\n'); --tabCount; elseStatement.append(indent("}")).append('\n'); } @@ -3241,8 +3299,14 @@ // require brackets on ifStatement unless the statement is just ";" if (!ifStatement.startsWith("{") && !ifStatement.equals(";")) { + if (bracketStyle == BROKEN) { + sb.append('\n').append(indent("{")).append('\n'); + } + else { + sb.append("{\n"); + } ++tabCount; - sb.append("{\n").append(indent(ifStatement)).append('\n'); + sb.append(indent(ifStatement)).append('\n'); --tabCount; sb.append(indent("}")).append('\n'); } @@ -3251,22 +3315,30 @@ } sb.append(elseStatement); - if (!endsWith(sb, "\n")) { + if (!endsWith(sb, "\n") && breakElse) { sb.append('\n'); } push(sb); } - private void formatFor(StatementContext ctx) { + private void formatFor() { // FOR '(' forControl ')' statement String statement = pop().trim(); // always require brackets if (!statement.startsWith("{")) { + StringBuilder sb = new StringBuilder(); + if (bracketStyle == BROKEN) { + sb.append('\n').append(indent("{")).append('\n'); + } + else { + sb.append(" {\n"); + } ++tabCount; - statement = " {\n" + indent(statement); + sb.append(indent(statement)).append('\n'); --tabCount; - statement += "\n}"; + sb.append(indent("}")); + statement = sb.toString(); } String rp = pop(); // ) @@ -3283,9 +3355,30 @@ push(sb); } - private void formatWhile(StatementContext ctx) { + private void formatWhile() { // WHILE parExpression statement String statement = pop().trim(); + + // always require brackets + if (!statement.startsWith("{")) { + StringBuilder sb = new StringBuilder(); + if (bracketStyle == BROKEN) { + sb.append('\n').append(indent("{")).append('\n'); + ++tabCount; + sb.append(indent(statement)).append('\n'); + --tabCount; + statement = sb.toString(); + } + else { + sb.append(" {\n"); + ++tabCount; + sb.append(indent(statement)).append('\n'); + --tabCount; + } + sb.append(indent("}")); + statement = sb.toString(); + } + String parExpression = pop(); String while_ = pop().trim(); // while keyword while_ = indent(while_); @@ -3294,19 +3387,31 @@ push(sb); } - private void formatDo(StatementContext ctx) { + private void formatDo() { // DO statement WHILE parExpression ';' String semi = pop(); // ; String parExpression = pop(); - String while_ = pop(); // while keyword + String while_ = indent(pop()); // while keyword String statement = pop().trim(); // always require brackets if (!statement.startsWith("{")) { - ++tabCount; - statement = " {\n" + indent(statement); - --tabCount; - statement =new StringBuilder(statement).append("\n}").toString(); + StringBuilder sb = new StringBuilder(); + if (bracketStyle == BROKEN) { + sb.append('\n').append(indent("{")).append('\n'); + ++tabCount; + sb.append(indent(statement)).append('\n'); + --tabCount; + statement = sb.toString(); + } + else { + sb.append(" {\n"); + ++tabCount; + sb.append(indent(statement)).append('\n'); + --tabCount; + } + sb.append(indent("}")); + statement = sb.toString(); } String do_ = pop(); // do keyword do_ = indent(do_); @@ -3355,7 +3460,14 @@ else { finallyBlock = pop(); } - String block = pop().trim(); + String block = pop(); + if (bracketStyle == BROKEN) { + block = new StringBuilder().append('\n').append(block).toString(); + } + else { + block = block.trim(); + } + String try_ = pop().trim(); // try keyword try_ = indent(try_); StringBuilder sb = new StringBuilder(); @@ -3386,6 +3498,12 @@ switchBlockStatementGroup = reverse(size, ""); } String lp = pop(); // { + if (bracketStyle == BROKEN) { + lp = new StringBuilder().append('\n').append(lp).toString(); + } + else { + lp = lp.trim(); + } String parExpression = pop(); String switch_ = pop().trim(); // switch keyword switch_ = indent(switch_); @@ -3407,9 +3525,15 @@ push(sb); } - private void formatSynchronized(StatementContext ctx) { + private void formatSynchronized(StatementContext ctx) { // NOPMD // SYNCHRONIZED parExpression block - String block = pop().trim(); + String block = pop(); + if (bracketStyle == BROKEN) { + block = new StringBuilder().append('\n').append(block).toString(); + } + else { + block = block.trim(); + } String parExpression = pop().trim(); String synchronized_ = pop().trim(); // synchronized keyword synchronized_ = indent(synchronized_); @@ -3478,7 +3602,7 @@ expression = new StringBuilder(indent).append(expression).toString(); } if (!expression.startsWith("\n")) { - expression = new StringBuilder('\n').append(expression).toString(); + expression = new StringBuilder("\n").append(expression).toString(); } } StringBuilder sb = new StringBuilder(); @@ -3486,7 +3610,7 @@ push(sb); } - private void formatColon(StatementContext ctx) { + private void formatColon() { // This is the only statement left with a colon // identifierLabel=identifier ':' statement // This is a labeled statement, section 14.7 of JLS 17 and should be formatted like: @@ -3552,7 +3676,7 @@ switchLabels = trimEnd(switchLabels) + ' '; } else if (!switchLabels.endsWith("\n")) { - switchLabels = switchLabels + '\n'; + switchLabels = switchLabels + '\n'; // NOPMD } StringBuilder sb = new StringBuilder(); @@ -3584,10 +3708,16 @@ int size = ctx.switchLabeledRule().size(); switchLabeledRule = reverse(size, ""); if (!switchLabeledRule.endsWith("\n")) { - switchLabeledRule += '\n'; + switchLabeledRule += '\n'; // NOPMD } } String lb = pop(); // { + if (bracketStyle == BROKEN) { + lb = new StringBuilder().append('\n').append(lb).toString(); + } + else { + lb = lb.trim(); + } String parExpression = pop(); String switch_ = pop(); // switch keyword switch_ = indent(switch_); @@ -3707,7 +3837,7 @@ String typeType = ""; if (ctx.typeType() != null) { typeType = pop(); - typeType = pop() + " " + typeType; // extends or super + typeType = pop() + " " + typeType; // NOPMD extends or super } String q = pop().trim(); // ? @@ -4068,10 +4198,6 @@ blankLinesBetweenImportGroups = lines; } - public void setBlankLinesAfterClassDeclaration(int lines) { - blankLinesAfterClassDeclaration = lines; - } - public void setBlankLinesAfterClassBody(int lines) { blankLinesAfterClassBody = lines; } @@ -4122,20 +4248,6 @@ } /** - * @return The indent in front of the given string. - */ - private String getIndent(String s) { - - String t = new String(s); - StringBuilder sb = new StringBuilder(); - while (t.length() > tab.length() && t.startsWith(tab)) { - sb.append(tab); - t = t.substring(tab.length()); - } - return sb.toString(); - } - - /** * Add tabCount tabs to the beginning of the given string builder. */ private void indent(StringBuilder sb) { @@ -4201,27 +4313,6 @@ return sb.toString(); } - /** - * Add blank lines to the end of the last item on the stack. Note that all - * blank lines are first removed then exactly <code>howMany</code> are added. - * @return true if blank lines were added to the last item on the stack, false - * if there were no items on the stack. - */ - private boolean addBlankLines(int howMany) { - if (!stack.isEmpty()) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < howMany + 1; i++) { - sb.append('\n'); - } - String ending = sb.toString(); - String last = pop(); - last = new StringBuilder(removeBlankLines(last, END)).append(ending).toString(); - push(last); - return true; - } - return false; - } - private String addBlankLines(StringBuilder sb, int howMany, int whichEnd) { return addBlankLines(sb.toString(), howMany, whichEnd); } @@ -4681,7 +4772,7 @@ if (last != null && last.indexOf(comment) == -1) { last = pop(); if (!comment.endsWith("\n")) { - comment += '\n'; + comment += '\n'; // NOPMD } last = new StringBuilder(comment).append(last).toString(); push(last); @@ -4879,7 +4970,7 @@ String[] lines = mod.split("\n"); for (String line : lines) { if (line.indexOf("//") > -1) { - lineComment += line + "\n"; + lineComment = new StringBuilder(lineComment).append(line).append('\n').toString(); } else { modifiers.set(i, lines[lines.length - 1]); @@ -4903,7 +4994,7 @@ String modifier = modifiers.get(i); modifier = modifier.trim(); if (modifier.startsWith("@") && !singleLine) { - modifier += '\n'; + modifier += '\n'; // NOPMD } sb.append(modifier); if (i < modifiers.size() - 1) { @@ -5137,11 +5228,14 @@ * ; */ private int getInterfaceMemberType(InterfaceMemberDeclarationContext ctx) { + if (ctx == null) { + return 0; + } // just a bunch of 'if's here if (ctx.constDeclaration() != null) { return CONST; } - if (ctx.interfaceMethodDeclaration() != null || ctx.interfaceMethodDeclaration() != null) { + if (ctx.interfaceMethodDeclaration() != null || ctx.genericInterfaceMethodDeclaration() != null) { return METHOD; } if (ctx.interfaceDeclaration() != null) { @@ -5176,7 +5270,7 @@ while (st.hasMoreTokens()) { String token = st.nextToken(); if (lineLength + token.length() > wrapLineLength) { - sb.append("\n"); + sb.append('\n'); lineLength = 0; } sb.append(token); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-09-02 21:24:50
|
Revision: 25598 http://sourceforge.net/p/jedit/svn/25598 Author: daleanson Date: 2022-09-02 21:24:47 +0000 (Fri, 02 Sep 2022) Log Message: ----------- Suitable for general usage, should work for Java 18 also. Modified Paths: -------------- plugins/Beauty/trunk/beauty.props plugins/Beauty/trunk/build.xml plugins/Beauty/trunk/services.xml plugins/Beauty/trunk/src/beauty/options/java/Java8OptionPane.java plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Added Paths: ----------- plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java plugins/Beauty/trunk/src/beauty/parsers/java/java/ErrorListener.java Modified: plugins/Beauty/trunk/beauty.props =================================================================== --- plugins/Beauty/trunk/beauty.props 2022-09-02 19:58:02 UTC (rev 25597) +++ plugins/Beauty/trunk/beauty.props 2022-09-02 21:24:47 UTC (rev 25598) @@ -6,12 +6,12 @@ plugin.beauty.BeautyPlugin.activate=defer plugin.beauty.BeautyPlugin.name=Beauty plugin.beauty.BeautyPlugin.author=Dale Anson -plugin.beauty.BeautyPlugin.version=1.0 +plugin.beauty.BeautyPlugin.version=1.0.01 plugin.beauty.BeautyPlugin.docs=docs/index.html -plugin.beauty.BeautyPlugin.depend.0=jdk 1.7 +plugin.beauty.BeautyPlugin.depend.0=jdk 1.8 plugin.beauty.BeautyPlugin.depend.1=jedit 05.04.00.00 plugin.beauty.BeautyPlugin.depend.2=plugin CommonControlsPlugin 1.7.4 -plugin.beauty.BeautyPlugin.depend.3=plugin antlr.AntlrPlugin 4.5.1 +plugin.beauty.BeautyPlugin.depend.3=plugin antlr.AntlrPlugin 4.10 plugin.beauty.BeautyPlugin.usePluginHome=true plugin.beauty.BeautyPlugin.description=The Beauty plugin is a general framework for code beautifiers and provides several built-in beautifiers. @@ -68,8 +68,9 @@ mode.java.beauty.beautifier=java mode.java.beauty.beautifier=java8 mode.javacc.beauty.beautifier=javacc +mode.csv.beauty.beautifier=csv +mode.json.beauty.beautifier=json - # Menus plugin.beauty.BeautyPlugin.menu=make_it_pretty Modified: plugins/Beauty/trunk/build.xml =================================================================== --- plugins/Beauty/trunk/build.xml 2022-09-02 19:58:02 UTC (rev 25597) +++ plugins/Beauty/trunk/build.xml 2022-09-02 21:24:47 UTC (rev 25598) @@ -1,4 +1,4 @@ -<project name="Beauty" default="dist" basedir="."> +<project name="Beauty" default="dist" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless"> <echo>${java.home}</echo> <!-- read build.props to override properties set below --> @@ -40,7 +40,7 @@ included in the finished jar file. --> <property name="classes.dir" location="${temp}/classes" /> - <property name="target.version" value="1.7"/> + <property name="target.version" value="11"/> <condition property="can.reload.plugins"> @@ -64,7 +64,7 @@ <!-- dependencies --> <pathelement location="${jedit.plugins.dir}/kappalayout.jar"/> - <pathelement location="${jedit.plugins.dir}/antlr4-4.5-opt.jar"/> + <pathelement location="${jedit.plugins.dir}/antlr-4.10.1-complete.jar"/> </path> </target> @@ -261,16 +261,33 @@ <target name="run" description="Run the application." - depends="setClasspath, compile"> - <java classname="beauty.parsers.java.antlr.Java8BeautyListener" fork="true"> + depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> <classpath refid="classpathref"/> <!-- <arg file="/home/danson/src/svnkit-1.8.5/src/src/svnkit-1.8.5/svnkit-test/src/main/java/org/tmatesoft/svn/core/test/PythonTests.java"/> --> - <arg file="/home/danson/tmp/test/ArraysAndDimsTest.java"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test files/BasicClass2.java"/> </java> </target> <target name="all" depends="javacc,dist"/> + + <target name="test" depends="setClasspath"> + <java classname="beauty.parsers.java.java.JavaParserBeautyListener" fork="true"> + <classpath refid="classpathref"/> + <arg file="/home/danson/src/jedit/plugins/Beauty/test/test files/java/before/IF_PERMITS.java"/> + <redirector + input="/home/danson/src/jedit/plugins/Beauty/test/test files/java/before/IF_PERMITS.java" + output="/home/danson/src/jedit/plugins/Beauty/test/test files/java/after/IF_PERMITS.java" /> + </java> + <condition property="test01passed" value="true"> + <filesmatch file1="/home/danson/src/jedit/plugins/Beauty/test/test files/java/after/IF_PERMITS.java" + file2="/home/danson/src/jedit/plugins/Beauty/test/test files/java/expected/IF_PERMITS.java" /> + </condition> + <echo if:set="test01passed">test01 passed</echo> + <echo unless:set="test01passed">test01 failed - did you remember to turn off tracing?</echo> + + </target> </project> Modified: plugins/Beauty/trunk/services.xml =================================================================== --- plugins/Beauty/trunk/services.xml 2022-09-02 19:58:02 UTC (rev 25597) +++ plugins/Beauty/trunk/services.xml 2022-09-02 21:24:47 UTC (rev 25598) @@ -3,7 +3,8 @@ <SERVICES> <SERVICE CLASS="beauty.beautifiers.Beautifier" NAME="java:beauty"> <!-- new beauty.beautifiers.JavaBeautifier(); --> - new beauty.beautifiers.Java8Beautifier(); + <!-- new beauty.beautifiers.Java8Beautifier(); --> + new beauty.beautifiers.Java17Beautifier(); </SERVICE> <SERVICE CLASS="beauty.beautifiers.Beautifier" NAME="javacc:beauty"> new beauty.beautifiers.JavaCCBeautifier(); @@ -23,4 +24,7 @@ <SERVICE CLASS="beauty.beautifiers.Beautifier" NAME="beanshell:beauty"> new beauty.beautifiers.BSHBeautifier(); </SERVICE> + <SERVICE CLASS="beauty.beautifiers.Beautifier" NAME="csv:beauty"> + new beauty.beautifiers.CSVBeautifier(); + </SERVICE> </SERVICES> Added: plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java =================================================================== --- plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java (rev 0) +++ plugins/Beauty/trunk/src/beauty/beautifiers/Java17Beautifier.java 2022-09-02 21:24:47 UTC (rev 25598) @@ -0,0 +1,136 @@ + +package beauty.beautifiers; + +import beauty.parsers.ParserException; +import beauty.parsers.java.java.*; + +import java.awt.*; +import java.io.*; +import java.util.*; + +import javax.swing.*; + +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.atn.PredictionMode; +import org.antlr.v4.runtime.misc.ParseCancellationException; +import org.antlr.v4.runtime.tree.*; +import org.gjt.sp.jedit.jEdit; + +// This is a newer parser based on Antlr and supports java 17 language. +public class Java17Beautifier extends Beautifier { + + private int bracketStyle = 1; // JavaParser.ATTACHED; + private boolean breakElse = false; + private boolean padParens = false; + private boolean padOperators = false; + private int blankLinesBeforePackage = 0; + private int blankLinesAfterPackage = 1; + private int blankLinesAfterImports = 2; + private boolean sortImports = true; + private boolean groupImports = true; + private int blankLinesBetweenImportGroups = 1; + private int blankLinesAfterClassDeclaration = 1; + private int blankLinesAfterClassBody = 2; + private int blankLinesBeforeMethods = 1; + private int blankLinesAfterMethods = 1; + private boolean sortModifiers = true; + private int collapseMultipleBlankLinesTo = 1; + private int wrapLongLineLength = 120; + + public void init() { + bracketStyle = jEdit.getIntegerProperty( "beauty.java.bracketStyle", JavaParserBeautyListener.ATTACHED ); + breakElse = jEdit.getBooleanProperty( "beauty.java.breakElse", true ); + padParens = jEdit.getBooleanProperty( "beauty.java.padParens", false ); + padOperators = jEdit.getBooleanProperty( "beauty.java.padOperators", false ); + blankLinesBeforePackage = jEdit.getIntegerProperty( "beauty.java8.blankLinesBeforePackage", 0 ); + blankLinesAfterPackage = jEdit.getIntegerProperty( "beauty.java8.blankLinesAfterPackage", 1 ); + blankLinesAfterImports = jEdit.getIntegerProperty( "beauty.java8.blankLinesAfterImports", 2 ); + sortImports = jEdit.getBooleanProperty( "beauty.java8.sortImports", true ); + groupImports = jEdit.getBooleanProperty( "beauty.java8.groupImports", true ); + blankLinesBetweenImportGroups = jEdit.getIntegerProperty( "beauty.java8.blankLinesBetweenImportGroups", 1 ); + blankLinesAfterClassDeclaration = jEdit.getIntegerProperty( "beauty.java8.blankLinesAfterClassDeclaration", 1 ); + blankLinesAfterClassBody = jEdit.getIntegerProperty( "beauty.java8.blankLinesAfterClassBody", 2 ); + blankLinesBeforeMethods = jEdit.getIntegerProperty( "beauty.java8.blankLinesBeforeMethods", 1 ); + blankLinesAfterMethods = jEdit.getIntegerProperty( "beauty.java8.blankLinesAfterMethods", 1 ); + sortModifiers = jEdit.getBooleanProperty( "beauty.java8.sortModifiers", true ); + collapseMultipleBlankLinesTo = jEdit.getIntegerProperty( "beauty.java8.collapseMultipleBlankLinesTo", 1 ); + wrapLongLineLength = jEdit.getIntegerProperty("beauty.java8.wrapLongLineLength", 120); + } + + public String beautify( String text ) throws ParserException { + + ErrorListener errorListener = null; + try { + + + // set up the parser + StringReader input = new StringReader( text ); + CharStream antlrInput = CharStreams.fromReader(input); + JavaLexer lexer = new JavaLexer( antlrInput ); + CommonTokenStream tokens = new CommonTokenStream( lexer ); + JavaParser javaParser = new JavaParser( tokens ); + + // for debugging + String trace = System.getProperty( "beauty.java.trace" ); + javaParser.setTrace( "true".equals( trace ) ); + + // set up the formatting options + JavaParserBeautyListener listener = new JavaParserBeautyListener( text.length() + 2048, tokens ); + listener.setIndentWidth( getIndentWidth() ); + listener.setUseSoftTabs( getUseSoftTabs() ); + listener.setBracketStyle( bracketStyle ); + listener.setBreakElse( breakElse ); + listener.setPadParens( padParens ); + listener.setPadOperators( padOperators ); + listener.setBlankLinesBeforePackage( blankLinesBeforePackage ); + listener.setBlankLinesAfterPackage( blankLinesAfterPackage ); + listener.setBlankLinesAfterImports( blankLinesAfterImports ); + listener.setSortImports( sortImports ); + listener.setGroupImports( groupImports ); + listener.setBlankLinesBetweenImportGroups( blankLinesBetweenImportGroups ); + listener.setBlankLinesAfterClassDeclaration( blankLinesAfterClassDeclaration ); + listener.setBlankLinesAfterClassBody( blankLinesAfterClassBody ); + listener.setBlankLinesBeforeMethods( blankLinesBeforeMethods ); + listener.setBlankLinesAfterMethods( blankLinesAfterMethods ); + listener.setSortModifiers( sortModifiers ); + listener.setCollapseMultipleBlankLinesTo( collapseMultipleBlankLinesTo ); + listener.setWrapLongLineLength(wrapLongLineLength); + + // add an error listener to the parser to capture any real errors + javaParser.removeErrorListeners(); + errorListener = new ErrorListener(); + javaParser.addErrorListener( errorListener ); + javaParser.setErrorHandler( new DefaultErrorStrategy() ); + + // parse the buffer text + ParseTreeWalker walker = new ParseTreeWalker(); + ParseTree tree = javaParser.compilationUnit(); + walker.walk( listener, tree ); + return listener.getText(); + } + catch ( Exception e ) { + java.util.List <ParserException> errors = errorListener.getErrors(); + if ( errors != null && errors.size() > 0 ) { + throw errors.get( 0 ); + } + else { + throw new ParserException( e ); + } + } + } + + public void setBracketStyle( int style ) { + bracketStyle = style; + } + + public void setBreakElse( boolean b ) { + breakElse = b; + } + + public void setPadParens( boolean pad ) { + padParens = pad; + } + +} + + Modified: plugins/Beauty/trunk/src/beauty/options/java/Java8OptionPane.java =================================================================== --- plugins/Beauty/trunk/src/beauty/options/java/Java8OptionPane.java 2022-09-02 19:58:02 UTC (rev 25597) +++ plugins/Beauty/trunk/src/beauty/options/java/Java8OptionPane.java 2022-09-02 21:24:47 UTC (rev 25598) @@ -23,6 +23,7 @@ private NumberTextField blankLinesAfterMethods; private JCheckBox sortModifiers; private NumberTextField collapseMultipleBlankLinesTo; + private NumberTextField wrapLongLinesLength; public Java8OptionPane() { super( new KappaLayout() ); @@ -76,6 +77,10 @@ collapseMultipleBlankLinesTo = new NumberTextField( 0, 100 ); collapseMultipleBlankLinesTo.setValue( jEdit.getIntegerProperty( "beauty.java8.collapseMultipleBlankLinesTo", 2 ) ); + JLabel wrapLongLinesLengthLabel = new JLabel( jEdit.getProperty( "beauty.java8.Wrap_Long_Line_Length", "Wrap Long Line Length" ) ); + wrapLongLinesLength = new NumberTextField( 0, 240 ); + wrapLongLinesLength.setValue( jEdit.getIntegerProperty( "beauty.java8.wrapLongLineLength", 120 ) ); + add( "0, 0, 1, 1, W, w, 3", description ); add( "0, 1, 1, 1, W, w, 3", blankLinesBeforePackageLabel ); add( "1, 1, 1, 1, W, w, 3", blankLinesBeforePackage ); @@ -98,6 +103,8 @@ add( "0, 11,1, 1, W, w, 3", sortModifiers ); add( "0, 12,1, 1, W, w, 3", collapseMultipleBlankLinesToLabel ); add( "1, 12,1, 1, W, w, 3", collapseMultipleBlankLinesTo ); + add( "0, 13,1, 1, W, w, 3", wrapLongLinesLengthLabel ); + add( "1, 13,1, 1, W, w, 3", wrapLongLinesLength ); } public void _save() { @@ -113,5 +120,6 @@ jEdit.setIntegerProperty( "beauty.java8.blankLinesAfterMethods", blankLinesAfterMethods.getValue() ); jEdit.setBooleanProperty( "beauty.java8.sortModifiers", sortModifiers.isSelected() ); jEdit.setIntegerProperty( "beauty.java8.collapseMultipleBlankLinesTo", collapseMultipleBlankLinesTo.getValue() ); + jEdit.setIntegerProperty( "beauty.java8.wrapLongLinesLength", wrapLongLinesLength.getValue()); } } Added: plugins/Beauty/trunk/src/beauty/parsers/java/java/ErrorListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/ErrorListener.java (rev 0) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/ErrorListener.java 2022-09-02 21:24:47 UTC (rev 25598) @@ -0,0 +1,30 @@ + +package beauty.parsers.java.java; + +import beauty.parsers.ParserException; + +import java.util.*; + +import org.antlr.v4.runtime.*; + +public class ErrorListener extends BaseErrorListener { + + private List<ParserException> errors = new ArrayList<ParserException>(); + + public List<ParserException> getErrors() { + return errors; + } + + public <T extends Token> void syntaxError( Recognizer<T, ?> recognizer, T offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e ) { + int length = 0; + if ( e != null && e.getOffendingToken() != null ) { + int startOffset = e.getOffendingToken().getStartIndex(); + int endOffset = e.getOffendingToken().getStopIndex(); + length = endOffset - startOffset; + } + + ParserException pe = new ParserException( msg, line, charPositionInLine, length ); + errors.add( pe ); + } +} + Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-02 19:58:02 UTC (rev 25597) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-02 21:24:47 UTC (rev 25598) @@ -80,6 +80,7 @@ private final int CLASS = 6; private final int ENUM = 7; private final int RECORD = 8; + private final int CONST = 9; /** * @param initialSize Initial size of the output buffer. @@ -523,8 +524,13 @@ // assemble the parts StringBuilder sb = new StringBuilder(); - // TODO: broken brackets - sb.append(lb); + if (brokenBracket) { + sb.append('\n'); + sb.append(indent(lb)); + } + else { + sb.append(lb); + } if (!blockStatements.isEmpty()) { if (!lb.endsWith("\n") && !blockStatements.startsWith("\n")) { sb.append('\n'); @@ -623,11 +629,14 @@ String lbrace = pop().trim(); StringBuilder sb = new StringBuilder(); - // TODO: fix this - //if (brokenBracket) { - // sb.append('\n'); - //} - sb.append(lbrace).append('\n'); + if (brokenBracket) { + sb.append('\n'); + sb.append(indent(lbrace)); + } + else { + sb.append(lbrace); + } + sb.append('\n'); if (!classBodyDecl.isEmpty()) { sb.append(classBodyDecl); if (!classBodyDecl.endsWith("\n")) { @@ -687,8 +696,7 @@ } // handle blank lines here, check the memberDeclaration for what it is (field, method, etc) - // and apply the blank line rules accordingly. Remove adding blank lines in the individual member - // exit methods. + // and apply the blank line rules accordingly. String decl = sb.toString(); decl = removeBlankLines(decl, BOTH); MemberDeclarationContext mdc = ctx.memberDeclaration(); @@ -1811,7 +1819,7 @@ sb.append(' '); } } - sb.append(lastFormalParameter); + sb.append(comma).append(' ').append(lastFormalParameter); push(sb); } } @@ -1920,7 +1928,6 @@ // second choice StringBuilder expression = new StringBuilder(); if (ctx.expression() != null) { - // TODO: why aren't I using reverse here? int size = ctx.expression().size(); List<String> parts = new ArrayList<String>(); for (int i = 0; i < size; i++) { @@ -2083,7 +2090,6 @@ push(sb); } else { - // TODO: handle blank lines here like in exitClassBody String decl = pop().trim(); String modifiers = ""; if (ctx.modifier() != null) { @@ -2092,7 +2098,28 @@ } modifiers = modifiers.isEmpty() ? getIndent() : indent(modifiers) + ' '; sb.append(modifiers).append(decl).append('\n'); - push(sb); + + // handle blank lines here, check the interfaceMemberDeclaration for what it is (field, method, etc) + // and apply the blank line rules accordingly. + decl = sb.toString(); + decl = removeBlankLines(decl, BOTH); + InterfaceMemberDeclarationContext mdc = ctx.interfaceMemberDeclaration(); + int type = getInterfaceMemberType(mdc); + switch(type) { + case CONST: + decl = addBlankLines(decl, 1, END); + break; + case METHOD: + case INTERFACE: + case ANNOTATION: + case CLASS: + case ENUM: + case RECORD: + default: + decl = addBlankLines(decl, 1, BOTH); + break; + } + push(decl); } } @@ -3233,13 +3260,14 @@ private void formatFor(StatementContext ctx) { // FOR '(' forControl ')' statement String statement = pop().trim(); - // TODO: always require brackets - /* + + // always require brackets if (!statement.startsWith("{")) { - statement = " {\n" + tab + statement.trim(); - statement += "\n}\n"; + ++tabCount; + statement = " {\n" + indent(statement); + --tabCount; + statement += "\n}"; } - */ String rp = pop(); // ) String forControl = pop(); @@ -3272,15 +3300,14 @@ String parExpression = pop(); String while_ = pop(); // while keyword String statement = pop().trim(); - // TODO: always require brackets - /* + + // always require brackets if (!statement.startsWith("{")) { ++tabCount; statement = " {\n" + indent(statement); --tabCount; - statement += "\n}"; + statement =new StringBuilder(statement).append("\n}").toString(); } - */ String do_ = pop(); // do keyword do_ = indent(do_); StringBuilder sb = new StringBuilder(); @@ -3448,10 +3475,10 @@ } else { if (!expression.startsWith(indent)) { - expression = indent + expression; + expression = new StringBuilder(indent).append(expression).toString(); } if (!expression.startsWith("\n")) { - expression = '\n' + expression; + expression = new StringBuilder('\n').append(expression).toString(); } } StringBuilder sb = new StringBuilder(); @@ -3467,8 +3494,6 @@ // statement // where label is outdented one tab and statement is indented with the current // tab count indenting - // TODO: if there is a comment attached to the label, should the comment also be outdented? - // At the moment, that is the how I'm handling it. String statement = pop(); statement = removeBlankLines(statement, BOTH); @@ -3980,8 +4005,6 @@ @Override public void visitErrorNode(ErrorNode node) { } - // TODO: should I trim every single terminalText? I do a lot of trimming, so - // I'm giving it a shot. @Override public void visitTerminal(TerminalNode node) { String terminalText = node.getText().trim(); push(terminalText); @@ -4157,19 +4180,6 @@ return sb.toString(); } - private String indentRBrace(String s) { - if (s.indexOf('}') > -1) { - StringBuilder sb = new StringBuilder(); - for ( int i = 0; i < tabCount - 1; i++ ) { - sb.append( tab ); - } - s = s.trim(); - sb.append(s); - return sb.toString(); - } - return s; // shouldn't happen - } - /** * Removes one tab from the beginning of each line in <code>s</code>. */ @@ -4853,9 +4863,6 @@ return ""; } - // TODO: the modifier might have a comment, need to deal with those. - // Actually, the comments appear to be handled correctly already. - // gather the modifiers into a list, then reverse the list so they are // in the right order List<String> modifiers = reverse(howMany); @@ -4951,7 +4958,7 @@ * removed. */ private static String removeComments(String s) { - String nc = new String(s); + String nc = new String(s); // NOPMD nc = nc.replaceAll("//.*?\\n", ""); nc = nc.replaceAll("/[*].*?[*]/", ""); return nc.trim(); @@ -5118,9 +5125,50 @@ } /** + * interfaceMemberDeclaration + * : constDeclaration + * | interfaceMethodDeclaration + * | genericInterfaceMethodDeclaration + * | interfaceDeclaration + * | annotationTypeDeclaration + * | classDeclaration + * | enumDeclaration + * | recordDeclaration // Java17 + * ; + */ + private int getInterfaceMemberType(InterfaceMemberDeclarationContext ctx) { + // just a bunch of 'if's here + if (ctx.constDeclaration() != null) { + return CONST; + } + if (ctx.interfaceMethodDeclaration() != null || ctx.interfaceMethodDeclaration() != null) { + return METHOD; + } + if (ctx.interfaceDeclaration() != null) { + return INTERFACE; + } + if (ctx.annotationTypeDeclaration() != null) { + return ANNOTATION; + } + if (ctx.classDeclaration() != null) { + return CLASS; + } + if (ctx.enumDeclaration() != null) { + return ENUM; + } + if (ctx.recordDeclaration() != null) { + return RECORD; + } + return 0; + } + + /** * Takes a long line as input, splits it into line of no more than <code>wrapLineLength</code>. */ private String wrapLongLine(String s) { + if (wrapLineLength == 0) { + return s; // 0 means don't wrap + } StringTokenizer st = new StringTokenizer(s, " "); StringBuilder sb = new StringBuilder(s.length()); sb.append('\n'); // it's a long line so start it on a new line This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-09-02 19:58:04
|
Revision: 25597 http://sourceforge.net/p/jedit/svn/25597 Author: daleanson Date: 2022-09-02 19:58:02 +0000 (Fri, 02 Sep 2022) Log Message: ----------- Working really well, onto fixing the TODO's. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-01 20:45:32 UTC (rev 25596) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-02 19:58:02 UTC (rev 25597) @@ -68,7 +68,8 @@ private int blankLinesBeforeMethods = 2; private int blankLinesAfterMethods = 1; private boolean sortModifiers = true; - private int collapseMultipleBlankLinesTo = 2; + private int collapseMultipleBlankLinesTo = 1; + private int wrapLineLength = 120; // declarations private final int METHOD = 1; @@ -459,8 +460,7 @@ } else { // check line length, if over 120, split the line - // TODO: make wrap length a setting - if (variableInitializer.length() > 120) { + if (variableInitializer.length() > wrapLineLength) { StringBuilder sb = new StringBuilder(); String[] parts = variableInitializer.split("[,]"); StringBuilder line = new StringBuilder("\n"); @@ -673,7 +673,7 @@ String modifiers = ""; if (ctx.modifier() != null && ctx.modifier().size() > 0) { int size = ctx.modifier().size(); - modifiers = formatModifiers(size, true); + modifiers = formatModifiers(size, false); } if (!modifiers.isEmpty()) { boolean hasNewLine = modifiers.endsWith("\n"); @@ -686,16 +686,22 @@ sb.append(memberDeclaration); } - // TODO: handle blank lines here, check the memberDeclaration for what it is (field, method, etc) + // handle blank lines here, check the memberDeclaration for what it is (field, method, etc) // and apply the blank line rules accordingly. Remove adding blank lines in the individual member // exit methods. String decl = sb.toString(); + decl = removeBlankLines(decl, BOTH); MemberDeclarationContext mdc = ctx.memberDeclaration(); int type = getMemberType(mdc); switch(type) { + case FIELD: + decl = addBlankLines(decl, 1, END); + break; + case CONSTRUCTOR: + decl = addBlankLines(decl, 1, START); + decl = addBlankLines(decl, 1, END); + break; case METHOD: - //case FIELD: - case CONSTRUCTOR: case INTERFACE: case ANNOTATION: case CLASS: @@ -702,7 +708,6 @@ case ENUM: case RECORD: default: - decl = removeBlankLines(decl, BOTH); decl = addBlankLines(decl, 1, BOTH); break; } @@ -710,7 +715,6 @@ } } - /** * classCreatorRest * : arguments classBody? @@ -876,7 +880,7 @@ } String importDeclarations = ""; - if (ctx.importDeclaration() != null) { + if (ctx.importDeclaration() != null && ctx.importDeclaration().size() > 0) { importDeclarations = sortAndGroupImports(reverse(ctx.importDeclaration().size())); importDeclarations = removeBlankLines(importDeclarations, BOTH); importDeclarations = removeExcessWhitespace(importDeclarations) + getBlankLines(blankLinesAfterImports); @@ -993,7 +997,6 @@ push(sb); } // otherwise, nothing to do as primitiveType should already be on the stack - // TODO: but is it indented? } /** @@ -1044,7 +1047,12 @@ * ; */ @Override public void exitElementValue(ElementValueContext ctx) { - // nothing to do here, one of the choices should already be on the stack + // check for long lines, wrap if needed + String element = stack.pop(); + if (element.length() > wrapLineLength) { + element = wrapLongLine(element); + } + push(element); } /** @@ -1051,7 +1059,6 @@ * elementValueArrayInitializer * : '{' (elementValue (',' elementValue)*)? (',')? '}' * ; - * TODO: wrap long lines? */ @Override public void exitElementValueArrayInitializer(ElementValueArrayInitializerContext ctx) { String rbrace = pop(); @@ -1082,6 +1089,7 @@ */ @Override public void exitElementValuePair(ElementValuePairContext ctx) { String value = pop(); + System.out.println("+++++ value>" + value + "<"); String equals = pop(); // equals String identifier = pop(); StringBuilder pair = new StringBuilder(); @@ -1103,7 +1111,7 @@ StringBuilder sb = new StringBuilder(); for (String part : parts) { part = part.trim(); - part = part.replace('\n', ' '); + //part = part.replace('\n', ' '); sb.append(part); if (part.equals(",")) { sb.append(' '); @@ -1149,6 +1157,7 @@ sb.append(part).append('\n'); } classBodyDeclaration = sb.toString(); + classBodyDeclaration = removeBlankLines(classBodyDeclaration, BOTH); } String semi = pop().trim(); // ; StringBuilder sb = new StringBuilder(); @@ -1263,7 +1272,7 @@ sb.append('\n'); } if (!enumConstants.isEmpty() || !comma.isEmpty() || !enumBodyDeclarations.isEmpty()) { - enumConstants = removeBlankLines(enumConstants, START); + enumConstants = removeBlankLines(enumConstants, BOTH); sb.append(enumConstants); if (!comma.isEmpty()) { sb.append(comma); @@ -1275,8 +1284,7 @@ } rb = removeBlankLines(rb, START); rb = indent(rb); - - sb.append(rb); + sb.append('\n').append(rb); if (!rb.endsWith("\n")) { sb.append('\n'); } @@ -1679,7 +1687,6 @@ push(sb); } // otherwise, the first expression is already on the stack - // TODO: does it need trimmed? } @@ -2012,7 +2019,6 @@ String classCreatorRest = pop().trim(); String args = ctx.nonWildcardTypeArgumentsOrDiamond() == null ? "" : pop(); String identifier = pop(); - // TODO: indent? StringBuilder sb = new StringBuilder(); sb.append(identifier).append(args).append(classCreatorRest); push(sb); @@ -2077,7 +2083,7 @@ push(sb); } else { - // TODO: handle blank lines here like in exitclassBody + // TODO: handle blank lines here like in exitClassBody String decl = pop().trim(); String modifiers = ""; if (ctx.modifier() != null) { @@ -2452,7 +2458,7 @@ StringBuilder sb = new StringBuilder(); sb.append(start); - if (lines > 1) { + if (lines > 1 && !expressionList.startsWith("\"\"\"")) { // don't worry about text blocks sb.append(lp).append('\n'); expressionList = removeBlankLines(expressionList, BOTH); sb.append(indentAgain(expressionList)); @@ -3899,6 +3905,10 @@ String equals = ""; if (ctx.variableInitializer() != null && ctx.ASSIGN() != null) { variableInitializer = pop().trim(); + if (variableInitializer.length() > wrapLineLength) { + variableInitializer = wrapLongLine(variableInitializer); + variableInitializer = indent(variableInitializer); + } equals = pop().trim(); } String variableDeclId = stack.pop(); @@ -4059,6 +4069,10 @@ collapseMultipleBlankLinesTo = lines; } + public void setWrapLongLineLength(int length) { + wrapLineLength = length; + } + //}}} /* -------------------------------------------------------------------------------- @@ -5103,7 +5117,25 @@ return 0; } - + /** + * Takes a long line as input, splits it into line of no more than <code>wrapLineLength</code>. + */ + private String wrapLongLine(String s) { + StringTokenizer st = new StringTokenizer(s, " "); + StringBuilder sb = new StringBuilder(s.length()); + sb.append('\n'); // it's a long line so start it on a new line + int lineLength = 0; + while (st.hasMoreTokens()) { + String token = st.nextToken(); + if (lineLength + token.length() > wrapLineLength) { + sb.append("\n"); + lineLength = 0; + } + sb.append(token); + lineLength += token.length(); + } + return sb.toString(); + } //}}} } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-09-01 20:45:34
|
Revision: 25596 http://sourceforge.net/p/jedit/svn/25596 Author: daleanson Date: 2022-09-01 20:45:32 +0000 (Thu, 01 Sep 2022) Log Message: ----------- Adjusted blank line handling, comment indenting, and other adjustments. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-26 21:15:31 UTC (rev 25595) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-09-01 20:45:32 UTC (rev 25596) @@ -70,7 +70,15 @@ private boolean sortModifiers = true; private int collapseMultipleBlankLinesTo = 2; - + // declarations + private final int METHOD = 1; + private final int FIELD = 2; + private final int CONSTRUCTOR = 3; + private final int INTERFACE = 4; + private final int ANNOTATION = 5; + private final int CLASS = 6; + private final int ENUM = 7; + private final int RECORD = 8; /** * @param initialSize Initial size of the output buffer. @@ -571,7 +579,7 @@ String variableModifiers = ""; if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); - variableModifiers = formatModifiers(size).trim(); + variableModifiers = formatModifiers(size, true).trim(); } String lb = pop(); // ( String catch_ = pop(); // catch keyword @@ -609,7 +617,8 @@ String classBodyDecl = ""; if (ctx.classBodyDeclaration() != null) { int size = ctx.classBodyDeclaration().size(); - classBodyDecl = reverse(size, "\n\n"); + classBodyDecl = reverse(size, ""); + classBodyDecl = removeBlankLines(classBodyDecl, START); } String lbrace = pop().trim(); @@ -619,8 +628,12 @@ // sb.append('\n'); //} sb.append(lbrace).append('\n'); - sb.append(classBodyDecl); - sb.append('\n'); + if (!classBodyDecl.isEmpty()) { + sb.append(classBodyDecl); + if (!classBodyDecl.endsWith("\n")) { + sb.append('\n'); + } + } sb.append(rbrace); push(sb); } @@ -657,11 +670,10 @@ else { String memberDeclaration = pop(); StringBuilder sb = new StringBuilder(); - //addBlankLines(sb, blankLinesBeforeMethods, START); String modifiers = ""; if (ctx.modifier() != null && ctx.modifier().size() > 0) { int size = ctx.modifier().size(); - modifiers = formatModifiers(size); + modifiers = formatModifiers(size, true); } if (!modifiers.isEmpty()) { boolean hasNewLine = modifiers.endsWith("\n"); @@ -673,7 +685,28 @@ else { sb.append(memberDeclaration); } - push(sb); + + // TODO: handle blank lines here, check the memberDeclaration for what it is (field, method, etc) + // and apply the blank line rules accordingly. Remove adding blank lines in the individual member + // exit methods. + String decl = sb.toString(); + MemberDeclarationContext mdc = ctx.memberDeclaration(); + int type = getMemberType(mdc); + switch(type) { + case METHOD: + //case FIELD: + case CONSTRUCTOR: + case INTERFACE: + case ANNOTATION: + case CLASS: + case ENUM: + case RECORD: + default: + decl = removeBlankLines(decl, BOTH); + decl = addBlankLines(decl, 1, BOTH); + break; + } + push(decl); } } @@ -915,10 +948,10 @@ String formalParameters = pop().trim(); String identifier = pop().trim(); identifier = indent(identifier); + StringBuilder sb = new StringBuilder(); sb.append(identifier).append(formalParameters).append(' ').append(throwsList).append(block); - String constructor = addBlankLines(sb, blankLinesAfterMethods, END); - push(constructor); + push(sb); } /** @@ -1093,7 +1126,7 @@ String variableModifiers = ""; if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); - variableModifiers = formatModifiers(size).trim(); + variableModifiers = formatModifiers(size, true).trim(); } StringBuilder sb = new StringBuilder(); sb.append(variableModifiers).append(' ').append(typeOrVar).append(' ').append(variableDeclaratorId).append(padOperator(colon)).append(expression); @@ -1737,7 +1770,7 @@ String modifiers = ""; if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); - modifiers = formatModifiers(size).trim(); + modifiers = formatModifiers(size, true).trim(); } StringBuilder sb = new StringBuilder(); sb.append(modifiers).append(' ').append(typeType).append(' ').append(id); @@ -1902,7 +1935,7 @@ String modifiers = ""; if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); - modifiers = formatModifiers(size).trim(); + modifiers = formatModifiers(size, true).trim(); } StringBuilder sb = new StringBuilder(); sb.append(modifiers).append(' ').append(typeType).append(' ').append(annotations).append(identifier).append(expression); @@ -2004,6 +2037,7 @@ * interfaceBody * : '{' interfaceBodyDeclaration* '}' * ; + * */ @Override public void exitInterfaceBody(InterfaceBodyContext ctx) { --tabCount; @@ -2024,10 +2058,7 @@ trimEnd(sb); rb = indent(rb); - if (!body.isEmpty()) { - sb.append('\n'); - } - sb.append(rb).append('\n'); + sb.append('\n').append(rb).append('\n'); push(sb); } @@ -2046,6 +2077,7 @@ push(sb); } else { + // TODO: handle blank lines here like in exitclassBody String decl = pop().trim(); String modifiers = ""; if (ctx.modifier() != null) { @@ -2219,7 +2251,7 @@ String modifiers = ""; if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); - modifiers = formatModifiers(size).trim(); + modifiers = formatModifiers(size, true).trim(); } StringBuilder sb = new StringBuilder(); sb.append(modifiers).append(' ').append(var_).append(' ').append(identifier); @@ -2276,7 +2308,7 @@ String modifiers = ""; if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); - modifiers = formatModifiers(size).trim(); + modifiers = formatModifiers(size, true).trim(); } StringBuilder sb = new StringBuilder(); sb.append(modifiers).append(' ').append(typeType).append(' ').append(annotations).append(ellipsis).append(id); @@ -2355,7 +2387,7 @@ String decl = type.toString(); if (ctx.variableModifier() != null && ctx.variableModifier().size() > 0) { int size = ctx.variableModifier().size(); - modifiers = formatModifiers(size); + modifiers = formatModifiers(size, true); modifiers = indent(modifiers); decl = trimFront(decl); } @@ -2401,11 +2433,6 @@ push(semi); } // otherwise, block is already on the stack - else { - String block = pop().trim(); - block = removeBlankLines(block, BOTH); - push(block); - } } /** @@ -2452,7 +2479,7 @@ * ; */ @Override public void exitMethodDeclaration(MethodDeclarationContext ctx) { - String methodBody = pop(); + String methodBody = pop().trim(); String throwsList = ""; if (ctx.THROWS() != null) { String qualifiedNameList = pop(); @@ -2699,7 +2726,7 @@ String modifiers = ""; if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); - modifiers = formatModifiers(size).trim(); + modifiers = formatModifiers(size, true).trim(); } StringBuilder sb = new StringBuilder(); if (!modifiers.isEmpty()) { @@ -2850,16 +2877,24 @@ */ @Override public void exitRecordBody(RecordBodyContext ctx) { --tabCount; - String rb = pop(); // } + String rb = pop().trim(); // } rb = indent(rb); String classBodyDeclaration = ""; - if (ctx.classBodyDeclaration() != null) { + if (ctx.classBodyDeclaration() != null && ctx.classBodyDeclaration().size() > 0) { int size = ctx.classBodyDeclaration().size(); classBodyDeclaration = reverse(size, ""); + classBodyDeclaration = removeBlankLines(classBodyDeclaration, START); } - String lb = pop(); // { + String lb = pop().trim(); // { StringBuilder sb = new StringBuilder(); - sb.append(lb).append('\n').append(classBodyDeclaration).append(rb).append('\n'); + sb.append(lb).append('\n'); + if (!classBodyDeclaration.isEmpty()) { + sb.append(classBodyDeclaration); + if (!classBodyDeclaration.endsWith("\n")) { + sb.append('\n'); + } + } + sb.append(rb).append('\n'); push(sb); } @@ -2901,13 +2936,22 @@ String implements_ = pop(); // implements keyword impl = implements_ + ' ' + typeList; } - String recordHeader = pop(); - String typeParameters = ctx.typeParameters() == null ? " " : pop(); + String recordHeader = pop().trim(); + String typeParameters = ctx.typeParameters() == null ? "" : pop(); String identifier = pop(); String record_ = pop(); // record keyword record_ = indent(record_); StringBuilder sb = new StringBuilder(); - sb.append(record_).append(' ').append(identifier).append(typeParameters).append(recordHeader).append(impl).append(recordBody); + sb.append(record_).append(' ').append(identifier); + if (typeParameters.isEmpty()) { + sb.append(typeParameters); + } + sb.append(recordHeader); + sb.append(' '); + if (!impl.isEmpty()) { + sb.append(impl).append(' '); + } + sb.append(recordBody); push(sb); } @@ -2917,11 +2961,16 @@ * ; */ @Override public void exitRecordHeader(RecordHeaderContext ctx) { - String rp = pop(); // ) - String list = ctx.recordComponentList() == null ? "" : pop(); - String lp = pop(); // ( + String rp = pop().trim(); // ) + String list = ctx.recordComponentList() == null ? "" : pop().trim(); + String lp = pop().trim(); // ( StringBuilder sb = new StringBuilder(); - sb.append(padParen(lp)).append(list).append(padParen(rp)); + if (list.isEmpty()) { + sb.append(lp).append(rp); + } + else { + sb.append(padParen(lp)).append(list).append(padParen(rp)); + } push(sb); } @@ -2960,7 +3009,7 @@ String modifiers = ""; if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); - modifiers = formatModifiers(size).trim(); + modifiers = formatModifiers(size, true).trim(); } StringBuilder sb = new StringBuilder(); sb.append(modifiers).append(' ').append(middle).append(padOperator(equals)).append(expression); @@ -3695,7 +3744,7 @@ */ @Override public void exitTypeDeclaration(TypeDeclarationContext ctx) { if (ctx.SEMI() != null) { - // append to previous stack item + // append semi to previous stack item String semi = pop().trim(); String previous = pop(); previous = trimEnd(previous); @@ -3800,7 +3849,7 @@ if (ann.indexOf('@') > -1) { // using indexOf to be able to check for altAnnotationQualifiedName // as well as regular annotation - endPart.append(pop()); // annotation + endPart.append(pop().trim()).append(' '); // annotation ++ annotationCount; } else { @@ -3816,7 +3865,7 @@ if (ctx.annotation() != null) { List<String> anns = reverse(ctx.annotation().size() - annotationCount); for (String a : anns) { - annotations.append(a).append(' '); + annotations.append(a.trim()).append(' '); } } @@ -4071,7 +4120,13 @@ String[] lines = s.split("\n"); String indent = getIndent(); for (String line : lines) { - sb.append(indent).append(line.trim()).append('\n'); + sb.append(indent); + line = line.trim(); + if (line.startsWith("*")) { + // odds are extremely high that this is a comment line + sb.append(' '); + } + sb.append(line).append('\n'); } return trimEnd(sb); } @@ -4147,6 +4202,13 @@ return addBlankLines(sb.toString(), howMany, whichEnd); } + /** + * Add blank lines to the given string. If <code>whichEnd</code> is START, this + * just adds <code>howMany</code> new line characters to the start of the string. + * If <code>whichEnd</code> is END, then this first checks for a trailing new + * line character, adds one if needed, then adds <code>howMany</code> new line + * characters to the end of the string. + */ private String addBlankLines(String s, int howMany, int whichEnd) { if (s == null || s.isEmpty()) { StringBuilder sb = new StringBuilder(); @@ -4155,7 +4217,13 @@ } return sb.toString(); } - + + // ensure the given string ends with a new line so that subsequent lines + // will actually be blank lines + if (whichEnd == END && !s.endsWith("\n")) { + ++howMany; + } + StringBuilder lines = new StringBuilder(); for (int i = 0; i < howMany; i++) { lines.append('\n'); @@ -4479,7 +4547,7 @@ } if (hasLineEnder) { // have "token comment \n", append this comment to the end - // of the previous item. + // of the token. StringBuilder item = new StringBuilder(pop()); String comment = nextCommentToken.getText(); if (item.indexOf(comment) == -1) { @@ -4753,11 +4821,26 @@ * @return The formatted modifiers. */ private String formatModifiers(int howMany) { + return formatModifiers(howMany, false); + } + + /** + * Pops <code>howMany</code> items from the stack. Assumes these items are modifiers + * for a constructor, method, field, or class. Formats the modifiers. Annotations + * are on a separate line above the other modifiers, remaining modifiers are separated + * by spaces. + * @param howMany The number of modifiers to pop off of the stack. + * @param singleLine If true, all modifiers are on a single line, if false, annotations + * will be on the first line and remaining modifiers a the second line. + * @return The formatted modifiers. + */ + private String formatModifiers(int howMany, boolean singleLine) { if (howMany <= 0) { return ""; } - // TODO: the modifier might have a comment, need to deal with those + // TODO: the modifier might have a comment, need to deal with those. + // Actually, the comments appear to be handled correctly already. // gather the modifiers into a list, then reverse the list so they are // in the right order @@ -4795,10 +4878,16 @@ if (!lineComment.isEmpty()) { sb.append(lineComment); } - for (String modifier : modifiers) { + for (int i = 0; i < modifiers.size(); i++) { + String modifier = modifiers.get(i); modifier = modifier.trim(); + if (modifier.startsWith("@") && !singleLine) { + modifier += '\n'; + } sb.append(modifier); - sb.append(modifier.startsWith("@") ? '\n' : ' '); + if (i < modifiers.size() - 1) { + sb.append(' '); + } } return sb.toString(); } @@ -4818,9 +4907,11 @@ private String modifiers = "public protected private abstract static final synchronized native sealed non-sealed strictfp transient volatile"; public int compare(String a, String b) { - String a_ = a.trim(); - String b_ = b.trim(); + // the modifier may have comments attaches, remove them before comparing + String a_ = removeComments(a); + String b_ = removeComments(b); + // annotations may be included in the choices if (a_.startsWith("@")) { return -1; @@ -4841,6 +4932,17 @@ } }; + /** + * Removes comments from the given string and trims whitespace after the comment is + * removed. + */ + private static String removeComments(String s) { + String nc = new String(s); + nc = nc.replaceAll("//.*?\\n", ""); + nc = nc.replaceAll("/[*].*?[*]/", ""); + return nc.trim(); + } + private String sortAndGroupImports(List<String> importList) { if (sortImports == false && groupImports == false) { StringBuilder sb = new StringBuilder(); @@ -4972,7 +5074,36 @@ return operator; } + private int getMemberType(MemberDeclarationContext ctx) { + // just a bunch of 'if's here + if (ctx.methodDeclaration() != null || ctx.genericMethodDeclaration() != null) { + return METHOD; + } + if (ctx.fieldDeclaration() != null) { + return FIELD; + } + if (ctx.constructorDeclaration() != null || ctx.genericConstructorDeclaration() != null) { + return CONSTRUCTOR; + } + if (ctx.interfaceDeclaration() != null) { + return INTERFACE; + } + if (ctx.annotationTypeDeclaration() != null) { + return ANNOTATION; + } + if (ctx.classDeclaration() != null) { + return CLASS; + } + if (ctx.enumDeclaration() != null) { + return ENUM; + } + if (ctx.recordDeclaration() != null) { + return RECORD; + } + return 0; + } + //}}} } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-08-26 21:15:34
|
Revision: 25595 http://sourceforge.net/p/jedit/svn/25595 Author: daleanson Date: 2022-08-26 21:15:31 +0000 (Fri, 26 Aug 2022) Log Message: ----------- daily commit, better every day, but not done Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-24 22:17:29 UTC (rev 25594) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-26 21:15:31 UTC (rev 25595) @@ -248,7 +248,7 @@ } @Override public void enterAnnotationTypeBody(AnnotationTypeBodyContext ctx) { - ++tabCount; + ++tabCount; } @@ -542,13 +542,12 @@ * ; */ @Override public void exitBlockStatement(BlockStatementContext ctx) { - if (ctx.SEMI() != null) { + if (ctx.SEMI() != null && ctx.localVariableDeclaration() != null) { String semi = pop().trim(); String localVariableDeclaration = pop(); StringBuilder sb = new StringBuilder(); sb.append(localVariableDeclaration).append(semi).append('\n'); - String decl = indent(sb.toString()) + '\n'; - push(decl); + push(sb); } else { String stmt = pop(); @@ -669,7 +668,7 @@ modifiers = indent(modifiers); sb.append(modifiers); sb.append(hasNewLine ? '\n' : ' '); - sb.append(memberDeclaration.trim()); + sb.append(trimFront(memberDeclaration)); } else { sb.append(memberDeclaration); @@ -1605,9 +1604,8 @@ } } - String expression1 = pop(); + String expression1 = pop().trim(); expression1 = removeBlankLines(expression1, BOTH); - expression1 = indent(expression1); StringBuilder sb = new StringBuilder(); sb.append(expression1); sb.append(padOperator(bop)); @@ -1871,11 +1869,11 @@ @Override public void exitGuardedPattern(GuardedPatternContext ctx) { if (ctx.RPAREN() != null) { // first choice - String rp = pop(); // ) - String guardedPattern = pop(); - String lp = pop(); // ( + String rp = pop().trim(); // ) + String guardedPattern = pop().trim(); + String lp = pop().trim(); // ( StringBuilder sb = new StringBuilder(); - sb.append(lp).append(guardedPattern).append(rp); + sb.append(padParen(lp)).append(guardedPattern).append(padParen(rp)); push(sb); } else if (ctx.typeType() != null) { @@ -1882,11 +1880,12 @@ // second choice StringBuilder expression = new StringBuilder(); if (ctx.expression() != null) { + // TODO: why aren't I using reverse here? int size = ctx.expression().size(); List<String> parts = new ArrayList<String>(); for (int i = 0; i < size; i++) { - parts.add(pop()); // expression - parts.add(padOperator(pop())); // && + parts.add(pop().trim()); // expression + parts.add(padOperator(pop().trim())); // && } Collections.reverse(parts); for (String part : parts) { @@ -1911,9 +1910,9 @@ } else { // third choice - String expression = pop(); - String amps = pop(); // && - String guardedPattern = pop(); + String expression = pop().trim(); + String amps = pop().trim(); // && + String guardedPattern = pop().trim(); StringBuilder sb = new StringBuilder(); sb.append(guardedPattern).append(padOperator(amps)).append(expression); push(sb); @@ -2307,7 +2306,7 @@ * (classDeclaration | interfaceDeclaration | recordDeclaration) * | ';' * ; - * This is idential to typeDeclaration + * This is identical to typeDeclaration */ @Override public void exitLocalTypeDeclaration(LocalTypeDeclarationContext ctx) { if (ctx.SEMI() != null) { @@ -2318,9 +2317,10 @@ } String declaration = pop(); String modifiers = ""; - if (ctx.classOrInterfaceModifier() != null) { + if (ctx.classOrInterfaceModifier() != null && ctx.classOrInterfaceModifier().size() > 0) { int size = ctx.classOrInterfaceModifier().size(); modifiers = formatModifiers(size).trim(); + declaration = declaration.trim(); } modifiers = indent(modifiers); StringBuilder sb = new StringBuilder(); @@ -2341,20 +2341,24 @@ String equals = padOperator(pop()); String identifier = pop(); String var_ = pop(); // var keyword + var_ = indent(var_); type.append(var_).append(' ').append(identifier).append(equals).append(expression); } else { String variableDecls = pop().trim(); String typeType = pop(); + typeType = indent(typeType); type.append(typeType).append(' ').append(variableDecls); } String modifiers = ""; - if (ctx.variableModifier() != null) { + String decl = type.toString(); + if (ctx.variableModifier() != null && ctx.variableModifier().size() > 0) { int size = ctx.variableModifier().size(); modifiers = formatModifiers(size); + modifiers = indent(modifiers); + decl = trimFront(decl); } - modifiers = indent(modifiers); StringBuilder sb = new StringBuilder(); sb.append(modifiers); @@ -2361,7 +2365,7 @@ if (!modifiers.isEmpty()) { sb.append(' '); } - sb.append(type); + sb.append(decl); push(sb); } @@ -2851,7 +2855,7 @@ String classBodyDeclaration = ""; if (ctx.classBodyDeclaration() != null) { int size = ctx.classBodyDeclaration().size(); - classBodyDeclaration = reverse(size, " "); + classBodyDeclaration = reverse(size, ""); } String lb = pop(); // { StringBuilder sb = new StringBuilder(); @@ -3026,9 +3030,14 @@ } @Override public void enterStatement(StatementContext ctx) { - if (ctx.SWITCH() != null || ctx.switchExpression() != null) { - ++tabCount; + if (ctx.switchExpression() != null) { + // do not increment the tabCount here. Note that ctx.SWITCH will not + // be null in this case + return; } + else if (ctx.SWITCH() != null) { + ++tabCount; + } } /** @@ -3078,7 +3087,6 @@ formatSwitch(ctx); } else if (ctx.switchExpression() != null) { - --tabCount; formatSwitchExpression(ctx); } else if (ctx.SYNCHRONIZED() != null) { @@ -3123,14 +3131,23 @@ private void formatIf(StatementContext ctx) { // IF parExpression statement (ELSE statement)? - // TODO: require brackets StringBuilder elseStatement = new StringBuilder(); if (ctx.ELSE() != null) { String es = pop().trim(); - String else_ = indent(pop()); // else keyword - elseStatement.append('\n'); + String else_ = indent(pop().trim()); // else keyword + //elseStatement.append('\n'); elseStatement.append(else_).append(' '); - elseStatement.append(es); + + // require brackets unless it's an "else if" statement + if (!es.startsWith("{") && !es.startsWith("if")) { + ++tabCount; + elseStatement.append("{\n").append(indent(es)).append('\n'); + --tabCount; + elseStatement.append(indent("}")).append('\n'); + } + else { + elseStatement.append(es); + } } String ifStatement = pop().trim(); @@ -3139,7 +3156,19 @@ StringBuilder sb = new StringBuilder(); sb.append(indent(if_)).append(' ').append(parExpression).append(' '); - sb.append(ifStatement).append(elseStatement); + + // require brackets on ifStatement unless the statement is just ";" + if (!ifStatement.startsWith("{") && !ifStatement.equals(";")) { + ++tabCount; + sb.append("{\n").append(indent(ifStatement)).append('\n'); + --tabCount; + sb.append(indent("}")).append('\n'); + } + else { + sb.append(ifStatement).append('\n'); + } + + sb.append(elseStatement); if (!endsWith(sb, "\n")) { sb.append('\n'); } @@ -3434,15 +3463,20 @@ @Override public void exitSwitchBlockStatementGroup(SwitchBlockStatementGroupContext ctx) { int size = ctx.blockStatement().size(); String blockStatements = reverse(size, ""); - blockStatements = indentAgain(blockStatements); size = ctx.switchLabel().size(); String switchLabels = reverse(size, ""); + if (blockStatements.trim().startsWith("{")) { + // it's a block + blockStatements = blockStatements.trim(); + switchLabels = trimEnd(switchLabels) + ' '; + } + else if (!switchLabels.endsWith("\n")) { + switchLabels = switchLabels + '\n'; + } + StringBuilder sb = new StringBuilder(); sb.append(switchLabels); - if (!switchLabels.endsWith("\n")) { - sb.append('\n'); - } sb.append(blockStatements); if (!blockStatements.endsWith("\n")) { sb.append('\n'); @@ -3530,9 +3564,12 @@ */ @Override public void exitSwitchLabeledRule(SwitchLabeledRuleContext ctx) { if (ctx.CASE() != null) { - String switchRuleOutcome = pop().trim(); - String operator = pop().trim(); - String choice = pop().trim(); + String switchRuleOutcome = ""; + if (ctx.switchRuleOutcome() != null) { + switchRuleOutcome = pop().trim(); + } + String operator = pop().trim(); // arrow or colon + String choice = pop().trim(); // expressionList, null, or guardedPattern String case_ = pop().trim(); case_ = indent(case_); StringBuilder sb = new StringBuilder(); @@ -3567,6 +3604,15 @@ } push(blockStatement.trim()); } + else if (ctx.block() == null) { + // no block and no blockStatements, need a placeholder on the stack, + // this could happen like this: + // case 1, 2: + // case 3, 4: + // blah... + // then case 1, 2: doesn't actually have a statement following it + push(""); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-08-24 22:17:31
|
Revision: 25594 http://sourceforge.net/p/jedit/svn/25594 Author: daleanson Date: 2022-08-24 22:17:29 +0000 (Wed, 24 Aug 2022) Log Message: ----------- Continuing fine tuning. It gets better day by day. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-10 23:43:49 UTC (rev 25593) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-24 22:17:29 UTC (rev 25594) @@ -64,7 +64,7 @@ private boolean groupImports = true; private int blankLinesBetweenImportGroups = 1; private int blankLinesAfterClassDeclaration = 1; - private int blankLinesAfterClassBody = 2; + private int blankLinesAfterClassBody = 1; private int blankLinesBeforeMethods = 2; private int blankLinesAfterMethods = 1; private boolean sortModifiers = true; @@ -136,11 +136,11 @@ ParseTree tree = javaParser.compilationUnit(); walker.walk( listener, tree ); - System.out.println("----- final output -----"); + //System.out.println("----- final output -----"); System.out.println(listener.getText()); - System.out.println("------------------------"); - long elapsed = System.currentTimeMillis() - startTime; - System.out.println("elapsed time: " + elapsed + " ms"); + //System.out.println("------------------------"); + //long elapsed = System.currentTimeMillis() - startTime; + //System.out.println("elapsed time: " + elapsed + " ms"); } catch (Exception e) { e.printStackTrace(); @@ -295,6 +295,7 @@ String identifier = pop(); String interface_ = pop(); // interface keyword String at = pop(); // @ + at = indent(at); StringBuilder sb = new StringBuilder(); sb.append(at).append(interface_).append(' ').append(identifier).append(' ').append(body); if (!body.endsWith("\n")) { @@ -365,7 +366,7 @@ String rp = pop(); // ) String expressionList = ""; if (ctx.expressionList() != null) { - expressionList = pop(); + expressionList = pop().trim(); } String lp = pop(); // ( StringBuilder sb = new StringBuilder(); @@ -409,8 +410,13 @@ if (ctx.expression() != null && ctx.expression().size() > 0) { size += ctx.expression().size(); } - String rest = reverse(size, ""); - push(rest); + + List<String>parts = reverse(size); + StringBuilder sb = new StringBuilder(); + for (String part : parts) { + sb.append(part.trim()); + } + push(sb); } @@ -429,17 +435,55 @@ String variableInitializer = reverse(size, " ", 2); String lb = pop().trim(); // { - String[] lines = variableInitializer.toString().split("\n"); + String[] lines = variableInitializer.split("\n"); if (lines.length > 1) { + // if it's multiple lines, just indent them, don't wrap because the lines + // are probably already arranged StringBuilder indented = new StringBuilder(); ++tabCount; for (String line : lines) { - indented.append(indent(line)); + indented.append(indent(line)).append('\n'); } --tabCount; indented.insert(0, '\n'); variableInitializer = indented.toString(); + rb = indent(rb); } + else { + // check line length, if over 120, split the line + // TODO: make wrap length a setting + if (variableInitializer.length() > 120) { + StringBuilder sb = new StringBuilder(); + String[] parts = variableInitializer.split("[,]"); + StringBuilder line = new StringBuilder("\n"); + int lineCount = 0; + for (int i = 0; i < parts.length; i++) { + String part = parts[i].trim(); + if (!part.isEmpty()) { + line.append(part); + line.append(", "); + } + if (line.length() >= 120) { + String l = line.toString(); + l = indent(l); + l = indentAgain(l); + sb.append(l); + ++lineCount; + line.delete(0, line.length()); + } + } + // last line + String l = line.toString(); + if (l.endsWith(", ")) { + l = l.substring(0, l.length() - 2); + } + l = indent(l); + l = indentAgain(l); + sb.append(l); + variableInitializer = sb.toString(); + rb = indent(rb); + } + } StringBuilder sb = new StringBuilder(); sb.append(lb).append(variableInitializer).append(rb); @@ -464,6 +508,7 @@ if (ctx.blockStatement() != null && ctx.blockStatement().size() > 0) { int size = ctx.blockStatement().size(); blockStatements = reverse(size, ""); + blockStatements = removeBlankLines(blockStatements, BOTH); } String lb = pop().trim(); lb = indent(lb); // need to indent in the case of a stand-alone block @@ -473,7 +518,9 @@ // TODO: broken brackets sb.append(lb); if (!blockStatements.isEmpty()) { - sb.append('\n'); + if (!lb.endsWith("\n") && !blockStatements.startsWith("\n")) { + sb.append('\n'); + } sb.append(blockStatements); if (!blockStatements.endsWith("\n")) { sb.append('\n'); @@ -598,7 +645,6 @@ if (ctx.block() != null) { String block = pop(); StringBuilder sb = new StringBuilder(); - //addBlankLines(sb, blankLinesBeforeMethods, START); if (ctx.STATIC() != null) { String static_ = pop(); // static keyword static_ = indent(static_); @@ -605,13 +651,12 @@ sb.append(static_).append(' '); block = block.trim(); } - //block = addBlankLines(block, blankLinesAfterMethods, END); sb.append(block); push(sb); return; } else { - String memberDeclaration = pop().trim(); + String memberDeclaration = pop(); StringBuilder sb = new StringBuilder(); //addBlankLines(sb, blankLinesBeforeMethods, START); String modifiers = ""; @@ -622,16 +667,12 @@ if (!modifiers.isEmpty()) { boolean hasNewLine = modifiers.endsWith("\n"); modifiers = indent(modifiers); - if (hasNewLine) { - sb.append(modifiers).append('\n').append(indent(memberDeclaration)); - } - else { - sb.append(modifiers).append(' ').append(memberDeclaration); - } + sb.append(modifiers); + sb.append(hasNewLine ? '\n' : ' '); + sb.append(memberDeclaration.trim()); } else { - String indent = getIndent(); - sb.append(indent).append(memberDeclaration); + sb.append(memberDeclaration); } push(sb); } @@ -797,8 +838,8 @@ else { String typeDeclarations = ""; if (ctx.typeDeclaration() != null) { - typeDeclarations = reverse(ctx.typeDeclaration().size(), "\n\n"); - typeDeclarations = removeBlankLines(typeDeclarations, BOTH) + '\n'; + typeDeclarations = reverse(ctx.typeDeclaration().size(), "\n"); + typeDeclarations = removeBlankLines(typeDeclarations, BOTH); typeDeclarations = removeExcessWhitespace(typeDeclarations); } @@ -876,8 +917,9 @@ String identifier = pop().trim(); identifier = indent(identifier); StringBuilder sb = new StringBuilder(); - sb.append(identifier).append(formalParameters).append(' ').append(throwsList).append(block).append('\n'); - push(sb); + sb.append(identifier).append(formalParameters).append(' ').append(throwsList).append(block); + String constructor = addBlankLines(sb, blankLinesAfterMethods, END); + push(constructor); } /** @@ -1045,7 +1087,7 @@ * ; */ @Override public void exitEnhancedForControl(EnhancedForControlContext ctx) { - String expression = pop(); + String expression = pop().trim(); String colon = pop(); // : String variableDeclaratorId = pop(); String typeOrVar = pop(); @@ -1069,7 +1111,12 @@ String classBodyDeclaration = ""; if (ctx.classBodyDeclaration() != null) { int size = ctx.classBodyDeclaration().size(); - classBodyDeclaration = reverse(size, "\n"); + StringBuilder sb = new StringBuilder(); + List<String> parts = reverse(size); + for (String part : parts) { + sb.append(part).append('\n'); + } + classBodyDeclaration = sb.toString(); } String semi = pop().trim(); // ; StringBuilder sb = new StringBuilder(); @@ -1179,11 +1226,15 @@ enum_ = indent(enum_); StringBuilder sb = new StringBuilder(); - sb.append(enum_).append(' ').append(identifier).append(' ').append(implements_).append(lb).append('\n'); + sb.append(enum_).append(' ').append(identifier).append(' ').append(implements_).append(lb); + if (!lb.endsWith("\n")) { + sb.append('\n'); + } if (!enumConstants.isEmpty() || !comma.isEmpty() || !enumBodyDeclarations.isEmpty()) { + enumConstants = removeBlankLines(enumConstants, START); sb.append(enumConstants); if (!comma.isEmpty()) { - sb.append(comma).append(' '); + sb.append(comma); } if (enumBodyDeclarations.trim().length() > 1) { enumBodyDeclarations = trimFront(enumBodyDeclarations); @@ -1190,8 +1241,13 @@ } sb.append(enumBodyDeclarations); } + rb = removeBlankLines(rb, START); rb = indent(rb); - sb.append(rb).append('\n'); + + sb.append(rb); + if (!rb.endsWith("\n")) { + sb.append('\n'); + } push(sb); } @@ -1417,7 +1473,7 @@ } if (ctx.typeType() != null && ctx.RPAREN() != null && ctx.LPAREN() != null) { // '(' annotation* typeType ('&' typeType)* ')' expression - String expression = pop(); + String expression = pop().trim(); String rp = pop(); // ) String typeTypes = ""; if (ctx.typeType().size() > 1) { @@ -1452,8 +1508,7 @@ if (typeTypes.length() > 0) { sb.append(' ').append(typeTypes); } - sb.append(rp); - sb.append(expression); + sb.append(rp).append(' ').append(expression); push(sb); return; } @@ -1504,7 +1559,7 @@ if (ctx.RBRACK() != null) { // expression '[' expression ']' String rb = pop(); // ] - String expression = pop(); + String expression = pop().trim(); String lb = pop(); // [ StringBuilder sb = new StringBuilder(pop()); sb.append(lb).append(expression).append(rb); @@ -1797,8 +1852,8 @@ * ; */ @Override public void exitGenericMethodDeclaration(GenericMethodDeclarationContext ctx) { - String method = pop(); - String typeParameters = pop(); + String method = pop().trim(); + String typeParameters = pop().trim(); typeParameters = indent(typeParameters); StringBuilder sb = new StringBuilder(); sb.append(typeParameters).append(' ').append(method); @@ -1953,7 +2008,7 @@ */ @Override public void exitInterfaceBody(InterfaceBodyContext ctx) { --tabCount; - String rb = pop(); // } + String rb = pop().trim(); // } String body = ""; if (ctx.interfaceBodyDeclaration() != null && ctx.interfaceBodyDeclaration().size() > 0) { @@ -1961,14 +2016,10 @@ body = removeBlankLines(body, BOTH); } - // TODO: what? why add blank lines after the left bracket? should be the right? - //addBlankLines(blankLinesAfterClassDeclaration); // added to left bracket - String lb = pop(); // { - + String lb = pop().trim(); // { + lb += '\n'; + StringBuilder sb = new StringBuilder(); - if (brokenBracket) { - sb.append('\n'); - } sb.append(lb); sb.append(body); @@ -2036,7 +2087,7 @@ annotations = reverse(size, " "); } StringBuilder sb = new StringBuilder(); - sb.append(annotations).append(typeTypeOrVoid).append(' ').append(identifier).append(' ').append(formalParameters).append(brackets).append(qualifiedNameList).append(methodBody); + sb.append(annotations).append(typeTypeOrVoid).append(' ').append(identifier).append(formalParameters).append(brackets).append(qualifiedNameList).append(methodBody); push(sb); } @@ -2850,6 +2901,7 @@ String typeParameters = ctx.typeParameters() == null ? " " : pop(); String identifier = pop(); String record_ = pop(); // record keyword + record_ = indent(record_); StringBuilder sb = new StringBuilder(); sb.append(record_).append(' ').append(identifier).append(typeParameters).append(recordHeader).append(impl).append(recordBody); push(sb); @@ -3193,10 +3245,17 @@ finallyBlock = pop(); } String block = pop().trim(); - String try_ = pop(); // try keyword + String try_ = pop().trim(); // try keyword try_ = indent(try_); StringBuilder sb = new StringBuilder(); - sb.append(try_).append(' ').append(block).append('\n').append(catchClause).append('\n').append(finallyBlock); + sb.append(try_).append(' ').append(block); + if (!catchClause.isEmpty()) { + sb.append('\n').append(catchClause); + } + if (!finallyBlock.isEmpty()) { + finallyBlock = removeBlankLines(finallyBlock, BOTH); + sb.append('\n').append(finallyBlock); + } push(sb); } } @@ -3815,8 +3874,11 @@ } @Override public void visitErrorNode(ErrorNode node) { } + + // TODO: should I trim every single terminalText? I do a lot of trimming, so + // I'm giving it a shot. @Override public void visitTerminal(TerminalNode node) { - String terminalText = node.getText(); + String terminalText = node.getText().trim(); push(terminalText); processComments(node); processWhitespace(node); @@ -4406,9 +4468,10 @@ String current = pop(); String previous = stack.peek(); push(current); - if (previous != null && previous.indexOf(comment) > -1 && previous.indexOf(comment.trim()) > -1) { - // already have this comment added as an end of line comment - // for the previous token + if (previous != null && previous.indexOf(comment) > -1 && previous.trim().endsWith(comment.trim())) { + // already have this comment added as an end of line comment to the right of the previous token. + // It's unlikely there would be two comments in a row with the exact same comment. If that were + // to actually happen, the second one will be dropped. continue; } switch(commentToken.getType()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-08-10 23:43:52
|
Revision: 25593 http://sourceforge.net/p/jedit/svn/25593 Author: daleanson Date: 2022-08-10 23:43:49 +0000 (Wed, 10 Aug 2022) Log Message: ----------- Continuing fine tuning. It gets better day by day. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-09 21:45:03 UTC (rev 25592) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-10 23:43:49 UTC (rev 25593) @@ -201,10 +201,13 @@ String name = pop().trim(); String at = ""; if (ctx.AT() != null) { - at = pop(); + at = pop().trim(); } StringBuilder annotation = new StringBuilder(); - annotation.append(at).append(name).append(elements).append('\n'); + annotation.append(at).append(name).append(elements); + if (!endsWith(elements, "\n")) { + annotation.append('\n'); + } push(annotation); } @@ -293,8 +296,12 @@ String interface_ = pop(); // interface keyword String at = pop(); // @ StringBuilder sb = new StringBuilder(); - sb.append(at).append(interface_).append(' ').append(identifier).append(' ').append(body).append('\n'); - push(sb); + sb.append(at).append(interface_).append(' ').append(identifier).append(' ').append(body); + if (!body.endsWith("\n")) { + sb.append('\n'); + } + String anno = removeBlankLines(sb.toString(), BOTH); + push(anno); } @@ -591,7 +598,7 @@ if (ctx.block() != null) { String block = pop(); StringBuilder sb = new StringBuilder(); - addBlankLines(sb, blankLinesBeforeMethods, START); + //addBlankLines(sb, blankLinesBeforeMethods, START); if (ctx.STATIC() != null) { String static_ = pop(); // static keyword static_ = indent(static_); @@ -598,7 +605,7 @@ sb.append(static_).append(' '); block = block.trim(); } - block = addBlankLines(block, blankLinesAfterMethods, END); + //block = addBlankLines(block, blankLinesAfterMethods, END); sb.append(block); push(sb); return; @@ -606,7 +613,7 @@ else { String memberDeclaration = pop().trim(); StringBuilder sb = new StringBuilder(); - addBlankLines(sb, blankLinesBeforeMethods, START); + //addBlankLines(sb, blankLinesBeforeMethods, START); String modifiers = ""; if (ctx.modifier() != null && ctx.modifier().size() > 0) { int size = ctx.modifier().size(); @@ -723,7 +730,7 @@ StringBuilder sb = new StringBuilder(); int size = ctx.identifier().size(); if (size == 1) { - // only 1 identifier + // only 1 identifier and maybe 1 typeArgument String typeArguments = ""; if (ctx.typeArguments() != null && ctx.typeArguments().size() > 0) { typeArguments = pop(); @@ -733,20 +740,9 @@ } else { // there are at least 2 identifiers - List<String> parts = new ArrayList<String>(); - for (int i = 0; i < size - 1; i++) { - String maybeType = stack.peek(); - if (maybeType.startsWith("<")) { - parts.add(pop()); // typeArguments - } - parts.add(pop()); // identifier - parts.add(pop()); // dot - } - parts.add(pop()); // first identifier - Collections.reverse(parts); - for (String part : parts) { - sb.append(part); - } + size += ctx.typeArguments().size() + ctx.DOT().size(); + String type = reverse(size, ""); + sb.append(type); } push(sb); } @@ -1463,7 +1459,12 @@ } if (ctx.INSTANCEOF() != null) { // expression bop=INSTANCEOF (typeType | pattern) + // 'typeType' may have annotations preceding it, and formatModifiers will + // put a new line following the annotation. The next few lines bring + // the 'instanceof" back to a single line expression. String typeOrPattern = pop(); + typeOrPattern = typeOrPattern.replace("\n", " "); + typeOrPattern = typeOrPattern.replace(" ", " "); String instanceOf = pop(); StringBuilder expression = new StringBuilder(pop()); expression.append(' ').append(instanceOf).append(' ').append(typeOrPattern); @@ -1961,7 +1962,7 @@ } // TODO: what? why add blank lines after the left bracket? should be the right? - addBlankLines(blankLinesAfterClassDeclaration); // added to left bracket + //addBlankLines(blankLinesAfterClassDeclaration); // added to left bracket String lb = pop(); // { StringBuilder sb = new StringBuilder(); @@ -3081,7 +3082,6 @@ } String ifStatement = pop().trim(); - System.out.println("+++++ ifStatement: " + ifStatement); String parExpression = pop(); String if_ = pop(); // if keyword @@ -3604,8 +3604,11 @@ StringBuilder typeDeclaration = new StringBuilder(); if (ctx.classOrInterfaceModifier() != null && ctx.classOrInterfaceModifier().size() > 0) { int size = ctx.classOrInterfaceModifier().size(); - String mods = formatModifiers(size).trim(); - typeDeclaration.append(mods).append(' '); + String mods = formatModifiers(size); // don't trim the modifies, it may be only an annotation, which should have a new line after it + typeDeclaration.append(mods); + if (!mods.endsWith("\n")) { + typeDeclaration.append(' '); + } } typeDeclaration.append(declaration); push(typeDeclaration); @@ -3679,7 +3682,7 @@ // handle the end part, (annotation* '[' ']')* StringBuilder endPart = new StringBuilder(); - if (ctx.RBRACK() != null && ctx.LBRACK() != null) { + if (ctx.RBRACK() != null && ctx.LBRACK() != null && ctx.RBRACK().size() > 0 && ctx.LBRACK().size() > 0) { for (int i = 0; i < ctx.RBRACK().size(); i++) { // get the brackets endPart.insert(0, pop()); // ] @@ -4084,20 +4087,28 @@ switch(whichEnd) { case START: index = sb.indexOf("\n"); - if (index > -1) { + while (index > -1) { String blank = sb.substring(0, index); if (isWhitespace(blank)) { sb.delete(0, index + 1); + index = sb.indexOf("\n"); } + else { + break; + } } break; case END: index = sb.lastIndexOf("\n"); - if (index > -1) { + while (index > -1) { String blank = sb.substring(index, sb.length()); if (isWhitespace(blank)) { sb.delete(index, sb.length()); + index = sb.lastIndexOf("\n"); } + else { + break; + } } break; case BOTH: @@ -4826,7 +4837,7 @@ } /** - * Removes all excess whitespace from the end each of the lines in <code>s</code>. + * Removes all excess whitespace from the end of each of the lines in <code>s</code>. */ private String removeExcessWhitespace(String s) { String[] lines = s.split("\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-08-09 21:45:06
|
Revision: 25592 http://sourceforge.net/p/jedit/svn/25592 Author: daleanson Date: 2022-08-09 21:45:03 +0000 (Tue, 09 Aug 2022) Log Message: ----------- Continuing fine tuning. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-08 22:44:13 UTC (rev 25591) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-09 21:45:03 UTC (rev 25592) @@ -163,9 +163,26 @@ init(); // initialize the formatting settings } - @Override public void exitAltAnnotationQualifiedName(AltAnnotationQualifiedNameContext ctx) { } /** + * altAnnotationQualifiedName + * : (identifier DOT)* '@' identifier + * ; + */ + @Override public void exitAltAnnotationQualifiedName(AltAnnotationQualifiedNameContext ctx) { + String identifier = pop(); + String at = pop(); + String start = ""; + if (ctx.DOT() != null && ctx.DOT().size() > 0) { + int size = ctx.DOT().size() * 2; + start = reverse(size, ""); + } + StringBuilder sb = new StringBuilder(); + sb.append(start).append(at).append(identifier); + push(sb); + } + + /** * annotation * : ('@' qualifiedName | altAnnotationQualifiedName) ('(' ( elementValuePairs | elementValue )? ')')? * ; @@ -176,15 +193,18 @@ String rp = pop(); // ) String element = ""; if (ctx.elementValue() != null || ctx.elementValuePairs() != null) { - element = pop(); + element = pop().trim(); } String lp = pop(); // ( elements.append(lp).append(element).append(rp); } - String name = pop(); + String name = pop().trim(); + String at = ""; + if (ctx.AT() != null) { + at = pop(); + } StringBuilder annotation = new StringBuilder(); - String at = pop(); - annotation.append(at).append(name).append(elements); + annotation.append(at).append(name).append(elements).append('\n'); push(annotation); } @@ -215,28 +235,34 @@ @Override public void exitAnnotationMethodRest(AnnotationMethodRestContext ctx) { String defaultValue = ""; if (ctx.defaultValue() != null) { - defaultValue = pop(); + defaultValue = pop().trim(); } - String rp = pop(); // ) - String lp = pop(); // ( + String rp = pop().trim(); // ) + String lp = pop().trim(); // ( StringBuilder identifier = new StringBuilder(pop()); - identifier.append(lp).append(rp).append(defaultValue); + identifier.append(lp).append(rp).append(' ').append(defaultValue); push(identifier); } + @Override public void enterAnnotationTypeBody(AnnotationTypeBodyContext ctx) { + ++tabCount; + } + + /** * annotationTypeBody * : '{' (annotationTypeElementDeclaration)* '}' * ; */ - @Override public void exitAnnotationTypeBody(AnnotationTypeBodyContext ctx) { - String rb = pop(); // } + @Override public void exitAnnotationTypeBody(AnnotationTypeBodyContext ctx) { + --tabCount; + String rb = pop().trim(); // } StringBuilder body = new StringBuilder(); - if (ctx.annotationTypeElementDeclaration() != null) { + if (ctx.annotationTypeElementDeclaration() != null && ctx.annotationTypeElementDeclaration().size() > 0) { int size = ctx.annotationTypeElementDeclaration().size(); List<String> parts = reverse(size); for (String part : parts) { - body.append(indent(part)); + body.append(part); } } String lb = pop(); @@ -243,11 +269,15 @@ StringBuilder sb = new StringBuilder(); if (!isWhitespace(body)) { sb.append(lb); - sb.append('\n').append(body).append('\n'); + sb.append('\n').append(body); + if (!endsWith(sb, "\n")) { + sb.append('\n'); + } + rb = indent(rb); sb.append(rb).append('\n'); } else { - sb.append(lb.trim()).append(rb.trim()).append('\n'); + sb.append(lb.trim()).append('\n').append(indent(rb.trim())).append('\n'); } push(sb); } @@ -258,17 +288,43 @@ * ; */ @Override public void exitAnnotationTypeDeclaration(AnnotationTypeDeclarationContext ctx) { - String body = pop(); + String body = pop().trim(); String identifier = pop(); String interface_ = pop(); // interface keyword String at = pop(); // @ StringBuilder sb = new StringBuilder(); - sb.append(at).append(interface_).append(' ').append(identifier).append(' ').append(body); + sb.append(at).append(interface_).append(' ').append(identifier).append(' ').append(body).append('\n'); push(sb); } - @Override public void exitAnnotationTypeElementDeclaration(AnnotationTypeElementDeclarationContext ctx) { } + /** + * annotationTypeElementDeclaration + * : modifier* annotationTypeElementRest + * | ';' // this is not allowed by the grammar, but apparently allowed by the actual compiler + * ; + */ + @Override public void exitAnnotationTypeElementDeclaration(AnnotationTypeElementDeclarationContext ctx) { + StringBuilder sb = new StringBuilder(); + if (ctx.SEMI() != null) { + String semi = pop().trim(); + sb.append(semi).append('\n'); + push(sb); + } + else { + String rest = pop(); + String modifiers = ""; + if (ctx.modifier() != null && ctx.modifier().size() > 0) { + int size = ctx.modifier().size(); + modifiers = formatModifiers(size).trim() + ' '; + } + modifiers = modifiers.isEmpty() ? getIndent() : indent(modifiers); + sb.append(modifiers).append(rest).append('\n'); + push(sb); + } + } + + /** * annotationTypeElementRest * : typeType annotationMethodOrConstantRest ';' * | classDeclaration ';'? @@ -279,21 +335,18 @@ * ; */ @Override public void exitAnnotationTypeElementRest(AnnotationTypeElementRestContext ctx) { + String semi = ""; if (ctx.SEMI() != null) { - String semi = pop(); // pop the semicolon - StringBuilder type = new StringBuilder(); - if (ctx.typeType() != null) { - List<String> parts = reverse(2); // typeType and annotationMethodOrConstantRest - for (int i = 0; i < 2; i++) { - type.append(parts.get(i)).append(' '); - } - } - else { - type.append(pop()); // one of the other 5 choices - } - type.append(semi); - push(type); + semi = pop().trim(); } + String decl = pop().trim(); + String typeType = ""; + if (ctx.typeType() != null) { + typeType = pop().trim() + ' '; + } + StringBuilder sb = new StringBuilder(); + sb.append(typeType).append(decl).append(semi); + push(sb); } /** @@ -406,6 +459,7 @@ blockStatements = reverse(size, ""); } String lb = pop().trim(); + lb = indent(lb); // need to indent in the case of a stand-alone block // assemble the parts StringBuilder sb = new StringBuilder(); @@ -417,13 +471,12 @@ if (!blockStatements.endsWith("\n")) { sb.append('\n'); } - rb = indent(rb); - sb.append(rb); } - else { - // { and } go on the same line: {} - sb.append(rb); - } + rb = indent(rb); + if (!endsWith(sb, "\n")) { + sb.append('\n'); + } + sb.append(rb); push(sb); } @@ -458,7 +511,7 @@ * ; */ @Override public void exitCatchClause(CatchClauseContext ctx) { - String block = pop(); + String block = pop().trim(); String rb = pop(); // ) String identifier = pop(); String catchType = pop(); @@ -543,6 +596,7 @@ String static_ = pop(); // static keyword static_ = indent(static_); sb.append(static_).append(' '); + block = block.trim(); } block = addBlankLines(block, blankLinesAfterMethods, END); sb.append(block); @@ -551,7 +605,6 @@ } else { String memberDeclaration = pop().trim(); - StringBuilder sb = new StringBuilder(); addBlankLines(sb, blankLinesBeforeMethods, START); String modifiers = ""; @@ -560,8 +613,14 @@ modifiers = formatModifiers(size); } if (!modifiers.isEmpty()) { + boolean hasNewLine = modifiers.endsWith("\n"); modifiers = indent(modifiers); - sb.append(modifiers).append(' ').append(memberDeclaration); + if (hasNewLine) { + sb.append(modifiers).append('\n').append(indent(memberDeclaration)); + } + else { + sb.append(modifiers).append(' ').append(memberDeclaration); + } } else { String indent = getIndent(); @@ -774,13 +833,13 @@ * ; */ @Override public void exitConstDeclaration(ConstDeclarationContext ctx) { - String semi = pop(); + String semi = pop().trim(); int size = ctx.constantDeclarator().size(); - String constantDeclarator = reverse(size * 2 - 1, " ", 2); - String typeType = pop(); + String constantDeclarator = reverse(size * 2 - 1, " ", 2).trim(); + String typeType = pop().trim(); typeType = indent(typeType); StringBuilder sb = new StringBuilder(); - sb.append(typeType).append(' ').append(constantDeclarator).append(semi); + sb.append(typeType).append(' ').append(constantDeclarator).append(semi).append('\n'); push(sb); } @@ -810,7 +869,7 @@ * ; */ @Override public void exitConstructorDeclaration(ConstructorDeclarationContext ctx) { - String block = pop(); + String block = pop().trim(); StringBuilder throwsList = new StringBuilder(); if (ctx.THROWS() != null) { String qualifiedNameList = pop().trim(); @@ -821,7 +880,7 @@ String identifier = pop().trim(); identifier = indent(identifier); StringBuilder sb = new StringBuilder(); - sb.append(identifier).append(formalParameters).append(' ').append(throwsList).append(block); + sb.append(identifier).append(formalParameters).append(' ').append(throwsList).append(block).append('\n'); push(sb); } @@ -926,24 +985,24 @@ */ @Override public void exitElementValueArrayInitializer(ElementValueArrayInitializerContext ctx) { String rbrace = pop(); - StringBuilder elements = new StringBuilder(); + StringBuilder sb = new StringBuilder(); if (ctx.elementValue() != null) { int size = ctx.elementValue().size(); if (ctx.COMMA() != null) { size += ctx.COMMA().size(); } - List<String> elementParts = reverse(size); - for (int i = 0; i < elementParts.size(); i++) { - elements.append(elementParts.get(i)); - if (i % 2 == 1) { - elements.append(' '); + List<String> parts = reverse(size); + for (String part : parts) { + sb.append(part.trim()); + if (part.equals(",")) { + sb.append(' '); } } } String lbrace = pop(); - elements.insert(0, lbrace); - elements.append(rbrace); - push(elements); + sb.insert(0, lbrace); + sb.append(rbrace); + push(sb); } /** @@ -967,8 +1026,20 @@ */ @Override public void exitElementValuePairs(ElementValuePairsContext ctx) { int size = ctx.elementValuePair().size(); - String pairs = reverse(size * 2 - 1, " ", 2); - push(pairs); + if (ctx.COMMA() != null) { + size += ctx.COMMA().size(); + } + List<String> parts = reverse(size); + StringBuilder sb = new StringBuilder(); + for (String part : parts) { + part = part.trim(); + part = part.replace('\n', ' '); + sb.append(part); + if (part.equals(",")) { + sb.append(' '); + } + } + push(sb); } @@ -1002,7 +1073,7 @@ String classBodyDeclaration = ""; if (ctx.classBodyDeclaration() != null) { int size = ctx.classBodyDeclaration().size(); - classBodyDeclaration = reverse(size, ""); + classBodyDeclaration = reverse(size, "\n"); } String semi = pop().trim(); // ; StringBuilder sb = new StringBuilder(); @@ -1023,7 +1094,7 @@ @Override public void exitEnumConstant(EnumConstantContext ctx) { String classBody = ""; if (ctx.classBody() != null) { - classBody = pop(); + classBody = pop(); } String arguments = ""; if (ctx.arguments() != null) { @@ -1042,11 +1113,13 @@ identifier = indent(identifier); } StringBuilder sb = new StringBuilder(); - sb.append(annotations).append(identifier).append(' '); + sb.append(annotations).append(identifier); if (arguments.length() > 0) { - sb.append(arguments).append(' '); + sb.append(' ').append(arguments); } - sb.append(classBody); + if (!classBody.isEmpty()) { + sb.append(' ').append(classBody); + } push(sb); } @@ -1063,15 +1136,23 @@ StringBuilder sb = new StringBuilder(); List<String> constants = reverse(size); for (int i = 0; i < size; i++) { - String constant = constants.get(i).trim(); - sb.append(constant); - if (constant.equals(",")) { - sb.append(' '); + String constant = constants.get(i); + long lines = constant.lines().count(); + if (lines == 1) { + sb.append(constant.trim()); + if (constant.equals(",")) { + sb.append(' '); + } } + else { + sb.append(constant); + if (constant.equals(",")) { + sb.append('\n'); + } + } } String enumConstants = sb.toString(); enumConstants = trimEnd(enumConstants); - enumConstants = indent(enumConstants); push(enumConstants); } @@ -1147,7 +1228,7 @@ String second = pop(); // superSuffix or arguments String first = pop(); // super keyword or identifier StringBuilder sb = new StringBuilder(); - sb.append(first).append(' ').append(second); + sb.append(first).append(second); push(sb); } @@ -1333,7 +1414,7 @@ String dot = pop(); // . bop StringBuilder expression = new StringBuilder(pop()); expression.append(dot); - expression.append(super_).append(' '); + expression.append(super_); expression.append(superSuffix); push(expression); return; @@ -1536,7 +1617,7 @@ * ; */ @Override public void exitFinallyBlock(FinallyBlockContext ctx) { - String block = pop(); + String block = pop().trim(); String finally_ = pop(); // finally keyword finally_ = indent(finally_); push(finally_ + ' ' + block); @@ -1619,15 +1700,24 @@ // only care about the first choice here, the second choice is already on the stack if (ctx.formalParameter() != null) { String lastFormalParameter = ""; + String comma = ""; if (ctx.lastFormalParameter() != null) { lastFormalParameter = pop(); - String comma = pop(); // , - lastFormalParameter = comma + ' ' + lastFormalParameter; + comma = pop(); // , } - int size = ctx.formalParameter().size(); - String formalParameter = size == 1 ? pop() : reverse(size * 2 - 1, " ", 2); + StringBuilder sb = new StringBuilder(); - sb.append(formalParameter).append(lastFormalParameter); + + int size = ctx.formalParameter().size() * 2 - 1; + List<String> parts = reverse(size); + for (String part : parts) { + part = part.trim(); + sb.append(part); + if (part.equals(",")) { + sb.append(' '); + } + } + sb.append(lastFormalParameter); push(sb); } } @@ -1642,17 +1732,19 @@ */ @Override public void exitFormalParameters(FormalParametersContext ctx) { StringBuilder sb = new StringBuilder(); - String rp = pop(); // ) + String rp = pop().trim(); // ) if (ctx.receiverParameter() != null && ctx.formalParameterList() != null) { + // second choice String formalParameterList = pop(); - String comma = pop(); + String comma = pop().trim(); String receiverParameter = pop(); - String lp = pop(); + String lp = pop().trim(); sb.append(padParen(lp)).append(receiverParameter).append(comma).append(' ').append(formalParameterList).append(padParen(rp)); } else if (ctx.receiverParameter() != null || ctx.formalParameterList() != null) { - String param = pop(); - String lp = pop(); + // first or third choice + String param = pop().trim(); + String lp = pop().trim(); sb.append(padParen(lp)).append(param).append(padParen(rp)); } else { @@ -1691,7 +1783,7 @@ int size = ctx.interfaceMethodModifier().size(); modifiers = formatModifiers(size).trim(); } - modifiers = indent(modifiers); + modifiers = modifiers.isEmpty() ? getIndent() : indent(modifiers); StringBuilder sb = new StringBuilder(); sb.append(modifiers).append(' ').append(typeParameters).append(' ').append(decl); push(sb); @@ -1895,22 +1987,24 @@ * ; */ @Override public void exitInterfaceBodyDeclaration(InterfaceBodyDeclarationContext ctx) { - if (ctx.interfaceMemberDeclaration() != null) { - String decl = pop(); + StringBuilder sb = new StringBuilder(); + if (ctx.SEMI() != null) { + String semi = pop().trim(); + //semi = indent(semi); + sb.append(semi).append('\n'); + push(sb); + } + else { + String decl = pop().trim(); String modifiers = ""; if (ctx.modifier() != null) { int size = ctx.modifier().size(); modifiers = formatModifiers(size).trim(); } - StringBuilder sb = new StringBuilder(); - sb.append(modifiers).append(' ').append(decl); + modifiers = modifiers.isEmpty() ? getIndent() : indent(modifiers) + ' '; + sb.append(modifiers).append(decl).append('\n'); push(sb); } - else { - String semi = pop(); - semi = indent(semi); - push(semi); - } } @@ -1920,7 +2014,7 @@ * ; */ @Override public void exitInterfaceCommonBodyDeclaration(InterfaceCommonBodyDeclarationContext ctx) { - String methodBody = pop(); + String methodBody = pop().trim(); StringBuilder qualifiedNameList = new StringBuilder(); if (ctx.qualifiedNameList() != null) { String list = pop(); @@ -1952,24 +2046,25 @@ * ; */ @Override public void exitInterfaceDeclaration(InterfaceDeclarationContext ctx) { - String interfaceBody = pop(); + String interfaceBody = pop().trim(); String permits_ = ""; - if (ctx.PERMITS() != null) { - String typeList = pop(); - permits_ = pop(); // permits keyword - permits_ += ' ' + typeList; + if (ctx.PERMITS() != null && ctx.typeList() != null && ctx.typeList().size() > 0) { + String typeList = pop().trim(); + permits_ = pop().trim(); // permits keyword + permits_ = new StringBuilder().append(' ').append(permits_).append(' ').append(typeList).toString(); } - StringBuilder extends_ = new StringBuilder(); - if (ctx.EXTENDS() != null) { - String typeList = pop(); - String extendsKeyword = pop(); - extends_.append(' ').append(extendsKeyword).append(' ').append(typeList); + String extends_ = ""; + if (ctx.EXTENDS() != null && ctx.typeList() != null && ctx.typeList().size() > 0) { + String typeList = pop().trim(); + String keyword = pop().trim(); // extends + extends_ = new StringBuilder().append(' ').append(keyword).append(' ').append(typeList).toString(); } - String typeParameters = ctx.typeParameters() == null ? "" : pop(); - String identifier = pop(); - String interface_ = pop(); // interface keyword + String typeParameters = ctx.typeParameters() == null ? "" : ' ' +pop(); + String identifier = pop().trim(); + String interface_ = pop().trim(); // interface keyword + interface_ = indent(interface_); StringBuilder sb = new StringBuilder(); - sb.append(interface_).append(' ').append(identifier).append(' ').append(typeParameters).append(extends_).append(permits_).append(interfaceBody); + sb.append(interface_).append(' ').append(identifier).append(typeParameters).append(extends_).append(permits_).append(' ').append(interfaceBody); push(sb); } @@ -2198,12 +2293,11 @@ } else { String variableDecls = pop().trim(); - String typeType = pop().trim(); + String typeType = pop(); type.append(typeType).append(' ').append(variableDecls); } String modifiers = ""; - StringBuilder variableModifiers = new StringBuilder(); if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); modifiers = formatModifiers(size); @@ -2252,7 +2346,7 @@ } // otherwise, block is already on the stack else { - String block = pop(); + String block = pop().trim(); block = removeBlankLines(block, BOTH); push(block); } @@ -2319,7 +2413,11 @@ String typeOrVoid = pop().trim(); typeOrVoid = indent(typeOrVoid); StringBuilder method = new StringBuilder(); - method.append(typeOrVoid).append(' ').append(identifier).append(formalParameters).append(' ').append(brackets).append(throwsList).append(methodBody); + method.append(typeOrVoid).append(' ').append(identifier).append(formalParameters).append(' ').append(brackets).append(throwsList); + if (!throwsList.isEmpty()) { + method.append(' '); + } + method.append(methodBody); push(method); } @@ -2536,7 +2634,7 @@ */ @Override public void exitPattern(PatternContext ctx) { String identifier = pop(); - String annotations = " "; + String annotations = ""; if (ctx.annotation() != null) { int size = ctx.annotation().size(); annotations = reverse(size, " "); @@ -2548,7 +2646,14 @@ modifiers = formatModifiers(size).trim(); } StringBuilder sb = new StringBuilder(); - sb.append(modifiers).append(' ').append(typeType).append(annotations).append(identifier); + if (!modifiers.isEmpty()) { + sb.append(modifiers).append(' '); + } + sb.append(typeType); + if (!annotations.isEmpty()) { + sb.append(annotations); + } + sb.append(' ').append(identifier); push(sb); } @@ -2952,7 +3057,7 @@ colon = pop().trim(); // : } expression = pop().trim(); - String assert_ = pop().trim(); // assert keyword + String assert_ = pop(); // assert keyword assert_ = indent(assert_); StringBuilder sb = new StringBuilder(); sb.append(assert_).append(' ').append(expression); @@ -2965,16 +3070,18 @@ private void formatIf(StatementContext ctx) { // IF parExpression statement (ELSE statement)? + // TODO: require brackets StringBuilder elseStatement = new StringBuilder(); if (ctx.ELSE() != null) { - String es = pop(); + String es = pop().trim(); String else_ = indent(pop()); // else keyword elseStatement.append('\n'); - elseStatement.append(else_); + elseStatement.append(else_).append(' '); elseStatement.append(es); } - String ifStatement = pop(); + String ifStatement = pop().trim(); + System.out.println("+++++ ifStatement: " + ifStatement); String parExpression = pop(); String if_ = pop(); // if keyword @@ -2989,7 +3096,7 @@ private void formatFor(StatementContext ctx) { // FOR '(' forControl ')' statement - String statement = pop(); + String statement = pop().trim(); // TODO: always require brackets /* if (!statement.startsWith("{")) { @@ -3006,12 +3113,15 @@ StringBuilder sb = new StringBuilder(); sb.append(for_).append(' ').append(padParen(lp)).append(forControl).append(padParen(rp)).append(' ').append(statement); + if (!statement.endsWith("\n")) { + sb.append('\n'); + } push(sb); } private void formatWhile(StatementContext ctx) { // WHILE parExpression statement - String statement = pop(); + String statement = pop().trim(); String parExpression = pop(); String while_ = pop().trim(); // while keyword while_ = indent(while_); @@ -3025,7 +3135,7 @@ String semi = pop(); // ; String parExpression = pop(); String while_ = pop(); // while keyword - String statement = pop(); + String statement = pop().trim(); // TODO: always require brackets /* if (!statement.startsWith("{")) { @@ -3053,7 +3163,7 @@ int size = ctx.catchClause().size(); catchClause = reverse(size, ""); } - String block = pop(); + String block = pop().trim(); String spec = pop(); String try_ = pop(); // try keyword try_ = indent(try_); @@ -3082,7 +3192,7 @@ else { finallyBlock = pop(); } - String block = pop(); + String block = pop().trim(); String try_ = pop(); // try keyword try_ = indent(try_); StringBuilder sb = new StringBuilder(); @@ -3179,11 +3289,12 @@ // SEMI // statementExpression=expression ';' String semi = pop().trim(); // ; - String expression = ""; - if (ctx.expression() != null) { - expression = pop(); + if (ctx.expression() == null || ctx.expression().size() == 0) { + push(semi); + return; } + String expression = pop(); long lines = expression.lines().count(); String indent = getIndent(); if (lines > 1) { @@ -3236,14 +3347,22 @@ * ; */ @Override public void exitSuperSuffix(SuperSuffixContext ctx) { - if (ctx.identifier() != null) { + if (ctx.DOT() != null && ctx.identifier() != null) { // second choice - String arguments = ctx.arguments() == null ? "" : " " + pop(); + String arguments = ctx.arguments() == null ? "" : pop(); String identifier = pop(); - String typeArguments = ctx.typeArguments() != null ? " " : pop(); + String typeArguments = ctx.typeArguments() == null ? "" : pop(); String dot = pop(); // . StringBuilder sb = new StringBuilder(); - sb.append(dot).append(typeArguments).append(identifier).append(arguments); + sb.append(dot); + if (!typeArguments.isEmpty()) { + sb.append(typeArguments); + } + sb.append(identifier); + if (!arguments.isEmpty()) { + sb.append(arguments); + } + push(sb); } // otherwise, arguments is already on the stack } @@ -3406,7 +3525,7 @@ typeType = pop() + " " + typeType; // extends or super } - String q = pop(); // ? + String q = pop().trim(); // ? String annotation = ""; if (ctx.annotation() != null) { int size = ctx.annotation().size(); @@ -3414,7 +3533,7 @@ } annotation = indent(annotation); StringBuilder sb = new StringBuilder(); - sb.append(annotation).append(padOperator(q)).append(typeType); + sb.append(annotation).append(q).append(typeType); push(sb); } } @@ -3483,12 +3602,10 @@ else { String declaration = pop(); StringBuilder typeDeclaration = new StringBuilder(); - if (ctx.classOrInterfaceModifier() != null) { - --tabCount; + if (ctx.classOrInterfaceModifier() != null && ctx.classOrInterfaceModifier().size() > 0) { int size = ctx.classOrInterfaceModifier().size(); String mods = formatModifiers(size).trim(); typeDeclaration.append(mods).append(' '); - ++tabCount; } typeDeclaration.append(declaration); push(typeDeclaration); @@ -3654,7 +3771,8 @@ variableDeclId.append(part); } } - variableDeclId.insert(0, pop().trim()); // identifier + String identifier = pop(); + variableDeclId.insert(0, identifier); push(variableDeclId); } @@ -4527,13 +4645,13 @@ // check for comments, if there is one or more single line comments (//...) // pull them out and save them for later. These comments should be in front - // of the modifier. + // of the modifier, unless it follows an annotation. // Keep inline comments (e.g. private /* words */ ) attached to the modifier // and let the sorter deal with them String lineComment = ""; for (int i = 0; i < modifiers.size(); i++) { String mod = modifiers.get(i); - if (mod.indexOf('\n') > -1 && mod.indexOf("//") > -1) { + if (mod.indexOf('\n') > -1 && mod.indexOf("//") > -1 && !mod.startsWith("@")) { String[] lines = mod.split("\n"); for (String line : lines) { if (line.indexOf("//") > -1) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-08-08 22:44:15
|
Revision: 25591 http://sourceforge.net/p/jedit/svn/25591 Author: daleanson Date: 2022-08-08 22:44:13 +0000 (Mon, 08 Aug 2022) Log Message: ----------- Continuing fine tuning. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-06 00:55:57 UTC (rev 25590) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-08 22:44:13 UTC (rev 25591) @@ -10,8 +10,10 @@ import java.util.regex.*; /** - * Beautifier for Java 17 and below. + Beautifier for Java 17 and below. + Reference Java Language Specification 17 Edition, https://docs.oracle.com/javase/specs/jls/se17/html/index.html + Notes about indenting: Parent sets the indent level on entry @@ -122,7 +124,7 @@ JavaLexer lexer = new JavaLexer( antlrInput ); CommonTokenStream tokens = new CommonTokenStream( lexer ); JavaParser javaParser = new JavaParser( tokens ); - //javaParser.setTrace(true); + javaParser.setTrace(true); // parse and beautify the buffer contents JavaParserBeautyListener listener = new JavaParserBeautyListener(16 * 1024, tokens); @@ -319,21 +321,36 @@ /** * arrayCreatorRest - * : '[' (']' ('[' ']')* arrayInitializer | expression ']' ('[' expression ']')* ('[' ']')*) + * : '[' + (']' ('[' ']')* + arrayInitializer | expression + ']' + ('[' expression ']')* + ('[' ']')*) * ; */ @Override public void exitArrayCreatorRest(ArrayCreatorRestContext ctx) { - // TODO: this is a pain and not right, in fact, I'm not sure the regular expression is correct - int size = ctx.LBRACK().size(); - size += ctx.RBRACK().size(); - if (ctx.expression() != null) { - size += ctx.expression().size(); + // context has: + // list of [ + // list of ] + // one array initializer, might be null + // list of expressions + + int size = 0; + if (ctx.LBRACK() != null && ctx.LBRACK().size() > 0) { + size += ctx.LBRACK().size(); } + if (ctx.RBRACK() != null && ctx.RBRACK().size() > 0) { + size += ctx.RBRACK().size(); + } if (ctx.arrayInitializer() != null) { - ++ size; + ++size; } - pop(size); - push(ctx.getText()); // TODO: this also drops any comments that may have been attached + if (ctx.expression() != null && ctx.expression().size() > 0) { + size += ctx.expression().size(); + } + String rest = reverse(size, ""); + push(rest); } @@ -345,19 +362,12 @@ @Override public void exitArrayInitializer(ArrayInitializerContext ctx) { String rb = pop(); // } - List<String> parts = new ArrayList<String>(); - while (!stack.peek().equals("{")) { - parts.add(stack.pop()); + int size = ctx.variableInitializer().size(); + if (ctx.COMMA() != null && ctx.COMMA().size() > 0) { + size += ctx.COMMA().size(); } - Collections.reverse(parts); - StringBuilder variableInitializer = new StringBuilder(); - for (String part : parts) { - variableInitializer.append(part); - if (part.equals(',')) { - variableInitializer.append(' '); - } - } - String lb = pop(); // { + String variableInitializer = reverse(size, " ", 2); + String lb = pop().trim(); // { String[] lines = variableInitializer.toString().split("\n"); if (lines.length > 1) { @@ -367,8 +377,8 @@ indented.append(indent(line)); } --tabCount; - variableInitializer = indented; - variableInitializer.insert(0, '\n'); + indented.insert(0, '\n'); + variableInitializer = indented.toString(); } StringBuilder sb = new StringBuilder(); @@ -426,14 +436,20 @@ */ @Override public void exitBlockStatement(BlockStatementContext ctx) { if (ctx.SEMI() != null) { - String semi = pop(); + String semi = pop().trim(); String localVariableDeclaration = pop(); StringBuilder sb = new StringBuilder(); - sb.append(localVariableDeclaration).append(semi); - push(indent(sb.toString())); + sb.append(localVariableDeclaration).append(semi).append('\n'); + String decl = indent(sb.toString()) + '\n'; + push(decl); } - // otherwise, just leave it alone, 'statement' and 'localTypeDeclaration' - // can be multi-line statements that should already be indented. + else { + String stmt = pop(); + if (stmt.startsWith("\n")) { + stmt = stmt.substring(1); + } + push(stmt); + } } /** @@ -453,8 +469,9 @@ } String lb = pop(); // ( String catch_ = pop(); // catch keyword - StringBuilder sb = new StringBuilder(catch_); - sb.append(padParen(lb)).append(variableModifiers).append(' ').append(catchType).append(' ').append(identifier).append(padParen(rb)).append(block); + catch_ = indent(catch_); + StringBuilder sb = new StringBuilder(); + sb.append(catch_).append(' ').append(padParen(lb)).append(variableModifiers).append(' ').append(catchType).append(' ').append(identifier).append(padParen(rb)).append(' ').append(block); push(sb); } @@ -466,7 +483,7 @@ */ @Override public void exitCatchType(CatchTypeContext ctx) { int size = ctx.qualifiedName().size(); - String qualifiedNames = reverse(size * 2 - 1, padOperator("|")); + String qualifiedNames = reverse(size * 2 - 1, " "); push(qualifiedNames); } @@ -729,6 +746,7 @@ typeDeclarations = removeBlankLines(typeDeclarations, BOTH) + '\n'; typeDeclarations = removeExcessWhitespace(typeDeclarations); } + String importDeclarations = ""; if (ctx.importDeclaration() != null) { importDeclarations = sortAndGroupImports(reverse(ctx.importDeclaration().size())); @@ -735,6 +753,7 @@ importDeclarations = removeBlankLines(importDeclarations, BOTH); importDeclarations = removeExcessWhitespace(importDeclarations) + getBlankLines(blankLinesAfterImports); } + String packageDeclaration = ""; if (ctx.packageDeclaration() != null) { packageDeclaration = pop(); @@ -1181,8 +1200,9 @@ */ @Override public void exitExpression(ExpressionContext ctx) { // a few of the choices can be skipped since they should already be on the stack - if (ctx.primary() != null) + if (ctx.primary() != null) { return; + } if (ctx.methodCall() != null && (ctx.expression() == null || ctx.expression().size() == 0)) { return; } @@ -1203,7 +1223,7 @@ push(sb); return; } - if (ctx.classType() != null || ctx.typeType() != null) { + if ((ctx.classType() != null || ctx.typeType() != null) && ctx.COLONCOLON() != null) { // classType '::' typeArguments? NEW // typeType '::' (typeArguments? identifier | NEW) // in typeType case, there is a NEW, so there won't be an identifier, @@ -1267,7 +1287,6 @@ push(expression); return; } - // all the rest of the cases have at least one expression int expressionCount = ctx.expression().size(); if (expressionCount == 1) { @@ -1293,16 +1312,16 @@ return; } if (ctx.NEW() != null) { - String innerCreator = pop(); + String innerCreator = pop().trim(); String typeArgs = ""; if (ctx.nonWildcardTypeArguments() != null) { typeArgs = pop() + ' '; } String new_ = pop(); // new keyword - String dot = pop(); // . bop + String dot = pop().trim(); // . bop StringBuilder expression = new StringBuilder(pop()); expression.append(dot); - expression.append(new_); + expression.append(new_).append(' '); expression.append(typeArgs); expression.append(innerCreator); push(expression); @@ -1371,24 +1390,29 @@ return; } - // there are 3 remaining cases with one expression: + // there are 3 remaining cases with one expression. postfix and prefix operators: // | expression postfix=('++' | '--') // | prefix=('+'|'-'|'++'|'--') expression // | prefix=('~'|'!') expression String post = stack.peek(); - if (post.indexOf('+') > -1 || post.indexOf('-') > -1) { + if (post.indexOf("++") > 1 || post.indexOf("--") > 1) { // it's the first case, the postfix expression - post = pop(); // ++ or -- - StringBuilder expression = new StringBuilder(pop()); - expression.append(post); - push(expression); + post = pop().trim(); // ++ or -- + String expression = pop(); + expression = removeBlankLines(expression, BOTH); + StringBuilder sb = new StringBuilder(); + sb.append(expression).append(post); + push(sb); return; } else { // it's one of the prefix expressions, and they are all the same - StringBuilder expression = new StringBuilder(pop()); - expression.append(padOperator(pop())); // one of + - ++ -- ~ ! - push(expression); + String expression = pop().trim(); + String pre = pop(); + pre = removeBlankLines(pre, BOTH); + StringBuilder sb = new StringBuilder(); + sb.append(pre).append(expression); + push(sb); return; } @@ -1422,7 +1446,30 @@ // expression String expression2 = pop().trim(); String bop = pop().trim(); - String expression1 = pop().trim(); + if (bop.equals("<") ) { + String peek = stack.peek(); + if (peek.equals("<")) { + stack.pop(); + bop = "<<"; + } + } + else if (bop.equals(">") ) { + String peek = stack.peek(); + if (peek.equals(">")) { + stack.pop(); + peek = stack.peek(); // might be >>> + if (peek.equals(">")) { + stack.pop(); + bop = ">>>"; + } + else { + bop = ">>"; + } + } + } + + String expression1 = pop(); + expression1 = removeBlankLines(expression1, BOTH); expression1 = indent(expression1); StringBuilder sb = new StringBuilder(); sb.append(expression1); @@ -1453,9 +1500,18 @@ @Override public void exitExpressionList(ExpressionListContext ctx) { int size = ctx.expression().size(); if (size > 1) { - String expression = reverse(size * 2 - 1, " ", 2); - push(expression); + StringBuilder sb = new StringBuilder(); + List<String> parts = reverse(size * 2 - 1); + for (String part : parts) { + sb.append(part.trim()); + if (part.equals(",")) { + sb.append(' '); + } + } + push(sb); } + // otherwise, the first expression is already on the stack + // TODO: does it need trimmed? } @@ -1507,13 +1563,21 @@ if (ctx.enhancedForControl() != null) { return; // it's already on the stack } - String expressionList = ctx.expressionList() == null ? "" : pop(); - String semi2 = pop(); // ; - String expression = ctx.expression() == null ? "" : pop(); - String semi1 = pop(); // ; - String forInit = ctx.forInit() == null ? "" : pop(); + String expressionList = ctx.expressionList() == null ? "" : pop().trim(); + String semi2 = pop().trim(); // ; + String expression = ctx.expression() == null ? "" : pop().trim(); + String semi1 = pop().trim(); // ; + String forInit = ctx.forInit() == null ? "" : pop().trim(); StringBuilder sb = new StringBuilder(); - sb.append(forInit).append(semi1).append(' ').append(expression).append(semi2).append(' ').append(expressionList); + sb.append(forInit).append(semi1); + if (!expression.isEmpty()) { + sb.append(' '); + } + sb.append(expression).append(semi2); + if (!expressionList.isEmpty()) { + sb.append(' '); + } + sb.append(expressionList); push(sb); } @@ -1765,8 +1829,8 @@ * ; */ @Override public void exitInnerCreator(InnerCreatorContext ctx) { - String classCreatorRest = pop(); - String args = ctx.nonWildcardTypeArgumentsOrDiamond() == null ? " " : pop(); + String classCreatorRest = pop().trim(); + String args = ctx.nonWildcardTypeArgumentsOrDiamond() == null ? "" : pop(); String identifier = pop(); // TODO: indent? StringBuilder sb = new StringBuilder(); @@ -2134,7 +2198,7 @@ } else { String variableDecls = pop().trim(); - String typeType = pop(); + String typeType = pop().trim(); type.append(typeType).append(' ').append(variableDecls); } @@ -2457,7 +2521,7 @@ */ @Override public void exitParExpression(ParExpressionContext ctx) { String rp = pop(); // ) - String expression = pop(); + String expression = pop().trim(); String lp = pop(); // ( StringBuilder sb = new StringBuilder(); sb.append(padParen(lp)).append(expression).append(padParen(rp)); @@ -2501,13 +2565,28 @@ */ @Override public void exitPrimary(PrimaryContext ctx) { if (ctx.RPAREN() != null) { - // first choice - String rp = pop(); // ) - String expression = pop(); - String lp = pop(); // ( - StringBuilder sb = new StringBuilder(); - sb.append(padParen(lp)).append(expression).append(padParen(rp)); - push(sb); + String rp = pop().trim(); // ) + String expression = ctx.expression() == null ? "" : pop(); + long lines = expression.lines().count(); + String lp = pop().trim(); // ( + + StringBuilder sb = new StringBuilder("\n"); + if (lines > 1) { + sb.append(lp).append('\n'); + expression = removeBlankLines(expression, BOTH); + sb.append(indentAgain(expression)); + sb.append(indent(rp)); + } + else { + if (!expression.isEmpty()) { + lp = padParen(lp); + rp = padParen(rp); + } + sb.append(lp); + sb.append(expression.trim()); + sb.append(rp); + } + push(sb); } else if (ctx.CLASS() != null) { // sixth choice @@ -2703,8 +2782,8 @@ @Override public void exitResource(ResourceContext ctx) { if (ctx.expression() != null) { // first choice - String expression = pop(); - String equals = pop(); // = + String expression = pop().trim(); + String equals = pop().trim(); // = String middle = ""; if (ctx.VAR() != null) { String identifier = pop(); @@ -2712,8 +2791,8 @@ middle = var_ + ' ' + identifier; } else { - String id = pop(); - String type = pop(); + String id = pop().trim(); + String type = pop().trim(); middle = type + ' ' + type; } String modifiers = ""; @@ -2732,6 +2811,7 @@ * resourceSpecification * : '(' resources ';'? ')' * ; + * Multiple resources are already on separate lines; */ @Override public void exitResourceSpecification(ResourceSpecificationContext ctx) { String rp = pop(); // ) @@ -2738,8 +2818,26 @@ String semi = ctx.SEMI() == null ? "" : pop(); String resources = pop(); String lp = pop(); // ( + StringBuilder sb = new StringBuilder(); - sb.append(padParen(lp)).append(resources).append(semi).append(padParen(rp)); + sb.append(padParen(lp)); + long lines = resources.lines().count(); + if (lines > 1) { + sb.append('\n'); + ++tabCount; + resources = indent(resources); + --tabCount; + sb.append(resources).append(semi); + if (!semi.endsWith("\n")) { + sb.append('\n'); + } + rp = indent(rp); + sb.append(rp); + } + else { + sb.append(resources.trim()); + sb.append(padParen(rp)); + } push(sb); } @@ -2747,10 +2845,26 @@ * resources * : resource (';' resource)* * ; + * If there are more than one resource, put them on separate lines. */ @Override public void exitResources(ResourcesContext ctx) { int size = ctx.resource().size(); - push(reverse(size * 2 - 1, " ", 2)); + if (size > 1) { + StringBuilder sb = new StringBuilder(); + List<String> parts = reverse(size * 2 - 1); + for (String part : parts) { + if (part.equals(";")) { + sb.append(part); + sb.append('\n'); + } + else { + part = indent(part); + sb.append(part); + } + } + push(sb); + } + // otherwise, the single resource is already on the stack } @Override public void enterStatement(StatementContext ctx) { @@ -2783,9 +2897,6 @@ * ; */ @Override public void exitStatement(StatementContext ctx) { - if (ctx.block() != null) { - return; // already on the stack - } if (ctx.ASSERT() != null) { formatAssert(ctx); } @@ -2827,23 +2938,29 @@ else if (ctx.COLON() != null) { formatColon(ctx); } + // block is the only remaining choice, and it should already be on the stack } private void formatAssert(StatementContext ctx) { // ASSERT expression (':' expression)? ';' - String semi = pop(); // ; + String semi = pop().trim(); // ; String expression = ""; String colon = ""; String expression2 = ""; - if (ctx.expression().size() > 1) { - expression2 = pop(); - colon = pop(); // : + if (ctx.expression().size() > 1 && ctx.COLON() != null) { + expression2 = pop().trim(); + colon = pop().trim(); // : } - expression = pop(); - String assert_ = pop(); // assert keyword + expression = pop().trim(); + String assert_ = pop().trim(); // assert keyword + assert_ = indent(assert_); StringBuilder sb = new StringBuilder(); - sb.append(assert_).append(' ').append(expression).append(padOperator(colon)).append(expression2).append(semi); - push(indent(sb.toString())); + sb.append(assert_).append(' ').append(expression); + if (!colon.isEmpty() && !expression2.isEmpty()) { + sb.append(padOperator(colon)).append(expression2); + } + sb.append(semi); + push(sb); } private void formatIf(StatementContext ctx) { @@ -2864,6 +2981,9 @@ StringBuilder sb = new StringBuilder(); sb.append(indent(if_)).append(' ').append(parExpression).append(' '); sb.append(ifStatement).append(elseStatement); + if (!endsWith(sb, "\n")) { + sb.append('\n'); + } push(sb); } @@ -2881,10 +3001,11 @@ String rp = pop(); // ) String forControl = pop(); String lp = pop(); // ( - String for_ = indent(pop()); // for keyword + String for_ = pop(); + for_ = indent(for_); StringBuilder sb = new StringBuilder(); - sb.append(for_).append(' ').append(padParen(lp)).append(forControl).append(' ').append(padParen(rp)).append(' ').append(statement); + sb.append(for_).append(' ').append(padParen(lp)).append(forControl).append(padParen(rp)).append(' ').append(statement); push(sb); } @@ -2891,8 +3012,8 @@ private void formatWhile(StatementContext ctx) { // WHILE parExpression statement String statement = pop(); - String parExpression = pop().trim(); - String while_ = pop(); // while keyword + String parExpression = pop(); + String while_ = pop().trim(); // while keyword while_ = indent(while_); StringBuilder sb = new StringBuilder(); sb.append(while_).append(' ').append(parExpression).append(' ').append(statement); @@ -2937,8 +3058,18 @@ String try_ = pop(); // try keyword try_ = indent(try_); StringBuilder sb = new StringBuilder(); - sb.append(try_).append(' ').append(spec).append(block).append(catchClause).append(finallyBlock); - push(sb); + sb.append(try_).append(' ').append(spec).append(block); + if (!block.endsWith("\n")) { + sb.append('\n'); + } + sb.append(catchClause); + if (!catchClause.endsWith("\n")) { + sb.append('\n'); + } + sb.append(finallyBlock); + String tryStatement = sb.toString(); + tryStatement = removeBlankLines(tryStatement, BOTH); + push(tryStatement); } else { String catchClause = ""; @@ -2955,7 +3086,7 @@ String try_ = pop(); // try keyword try_ = indent(try_); StringBuilder sb = new StringBuilder(); - sb.append(try_).append(' ').append(block).append(catchClause).append(finallyBlock); + sb.append(try_).append(' ').append(block).append('\n').append(catchClause).append('\n').append(finallyBlock); push(sb); } } @@ -2998,12 +3129,15 @@ private void formatSynchronized(StatementContext ctx) { // SYNCHRONIZED parExpression block - String block = pop(); - String parExpression = pop(); - String synchronized_ = pop(); // synchronized keyword + String block = pop().trim(); + String parExpression = pop().trim(); + String synchronized_ = pop().trim(); // synchronized keyword synchronized_ = indent(synchronized_); StringBuilder sb = new StringBuilder(); sb.append(synchronized_).append(' ').append(parExpression).append(block); + if (!block.endsWith("\n")) { + sb.append('\n'); + } push(sb); } @@ -3013,11 +3147,18 @@ // THROW expression ';' // YIELD expression ';' String semi = pop().trim(); //; - String expression = ctx.expression() == null ? "" : pop().trim(); + String expression = ""; + if (ctx.expression() != null && ctx.expression().size() > 0) { + expression = pop().trim(); + } String keyword = pop().trim(); keyword = indent(keyword); StringBuilder sb = new StringBuilder(); - sb.append(keyword).append(' ').append(expression).append(semi); + sb.append(keyword); + if (!expression.isEmpty()) { + sb.append(' '); + } + sb.append(expression).append(semi); push(sb); } @@ -3042,25 +3183,48 @@ if (ctx.expression() != null) { expression = pop(); } + long lines = expression.lines().count(); + String indent = getIndent(); if (lines > 1) { - expression = getIndent() + expression.trim(); + expression = removeBlankLines(expression, END); + if (!expression.startsWith(indent)) { + expression = indent(expression); + } } + else { + if (!expression.startsWith(indent)) { + expression = indent + expression; + } + if (!expression.startsWith("\n")) { + expression = '\n' + expression; + } + } StringBuilder sb = new StringBuilder(); sb.append(expression).append(semi).append('\n'); push(sb); - } private void formatColon(StatementContext ctx) { - // this is the only statement left with a colon + // This is the only statement left with a colon // identifierLabel=identifier ':' statement + // This is a labeled statement, section 14.7 of JLS 17 and should be formatted like: + // label: + // statement + // where label is outdented one tab and statement is indented with the current + // tab count indenting + // TODO: if there is a comment attached to the label, should the comment also be outdented? + // At the moment, that is the how I'm handling it. + String statement = pop(); - String colon = pop(); // : + statement = removeBlankLines(statement, BOTH); + String colon = pop().trim(); // : String identifier = pop(); + // indent to current tab count, then outdent one tab identifier = indent(identifier); + identifier = outdent(identifier); StringBuilder sb = new StringBuilder(); - sb.append(identifier).append(padOperator(colon)).append(statement); + sb.append(identifier).append(colon).append('\n').append(statement); push(sb); } @@ -3151,7 +3315,7 @@ */ @Override public void exitSwitchLabel(SwitchLabelContext ctx) { if (ctx.DEFAULT() != null) { - String colon = pop(); + String colon = pop().trim(); String default_ = pop(); // default keyword default_ = indent(default_); StringBuilder sb = new StringBuilder(); @@ -3172,7 +3336,7 @@ String case_ = pop().trim(); case_ = indent(case_); StringBuilder sb = new StringBuilder(); - sb.append(case_).append(' ').append(label).append(colon); + sb.append(case_).append(' ').append(label).append(colon).append('\n'); push(sb); } } @@ -3307,19 +3471,28 @@ */ @Override public void exitTypeDeclaration(TypeDeclarationContext ctx) { if (ctx.SEMI() != null) { - return; // Just a semicolon in the type declaration, it should already be on the stack + // append to previous stack item + String semi = pop().trim(); + String previous = pop(); + previous = trimEnd(previous); + StringBuilder sb = new StringBuilder(); + sb.append(previous).append(semi).append('\n'); + push(sb); + push("\n"); // need a type declaration placeholder since 2 are combined above } - String declaration = pop(); - StringBuilder typeDeclaration = new StringBuilder(); - if (ctx.classOrInterfaceModifier() != null) { - --tabCount; - int size = ctx.classOrInterfaceModifier().size(); - String mods = formatModifiers(size).trim(); - typeDeclaration.append(mods).append(' '); - ++tabCount; + else { + String declaration = pop(); + StringBuilder typeDeclaration = new StringBuilder(); + if (ctx.classOrInterfaceModifier() != null) { + --tabCount; + int size = ctx.classOrInterfaceModifier().size(); + String mods = formatModifiers(size).trim(); + typeDeclaration.append(mods).append(' '); + ++tabCount; + } + typeDeclaration.append(declaration); + push(typeDeclaration); } - typeDeclaration.append(declaration); - push(typeDeclaration); } /** @@ -3452,12 +3625,17 @@ String equals = ""; if (ctx.variableInitializer() != null && ctx.ASSIGN() != null) { variableInitializer = pop().trim(); - equals = padOperator(pop().trim()); + equals = pop().trim(); } + String variableDeclId = stack.pop(); + StringBuilder variableDecl = new StringBuilder(); - variableDecl.append(pop().trim()); // variableDeclaratorId - variableDecl.append(padOperator(equals)); - variableDecl.append(variableInitializer.trim()); + variableDecl.append(variableDeclId); + if (!equals.isEmpty() && !variableInitializer.isEmpty()) { + variableDecl.append(padOperator(equals)); + variableDecl.append(variableInitializer); + } + push(variableDecl); } @@ -3709,6 +3887,9 @@ sb.append('\n'); } } + if (!s.endsWith("\n")) { + sb.deleteCharAt(sb.length() - 1); + } return sb.toString(); } @@ -4077,6 +4258,12 @@ // ... // Line, Regular, and Doc Comments, and jEdit fold markers + // A line comment is like this line + // /* A regular comment is like this one, and could span several lines */ + // /** + // * A doc comment is like this one, double asterisk at the start and + // * could also span several lines + // */ // ... // check to the left of the current token for line. regular, and doc comments commentTokens = tokens.getHiddenTokensToLeft(tokenIndex, 2); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-08-06 00:55:59
|
Revision: 25590 http://sourceforge.net/p/jedit/svn/25590 Author: daleanson Date: 2022-08-06 00:55:57 +0000 (Sat, 06 Aug 2022) Log Message: ----------- Continuing fine tuning, switch is working well now. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-02 22:45:37 UTC (rev 25589) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-06 00:55:57 UTC (rev 25590) @@ -122,7 +122,7 @@ JavaLexer lexer = new JavaLexer( antlrInput ); CommonTokenStream tokens = new CommonTokenStream( lexer ); JavaParser javaParser = new JavaParser( tokens ); - javaParser.setTrace(true); + //javaParser.setTrace(true); // parse and beautify the buffer contents JavaParserBeautyListener listener = new JavaParserBeautyListener(16 * 1024, tokens); @@ -388,10 +388,10 @@ @Override public void exitBlock(BlockContext ctx) { --tabCount; - String rb = pop(); + String rb = pop().trim(); String blockStatements = ""; - if (ctx.blockStatement() != null) { + if (ctx.blockStatement() != null && ctx.blockStatement().size() > 0) { int size = ctx.blockStatement().size(); blockStatements = reverse(size, ""); } @@ -402,10 +402,18 @@ // TODO: broken brackets sb.append(lb); if (!blockStatements.isEmpty()) { - sb.append('\n'); + sb.append('\n'); + sb.append(blockStatements); + if (!blockStatements.endsWith("\n")) { + sb.append('\n'); + } rb = indent(rb); + sb.append(rb); } - sb.append(blockStatements).append('\n').append(rb); + else { + // { and } go on the same line: {} + sb.append(rb); + } push(sb); } @@ -424,10 +432,8 @@ sb.append(localVariableDeclaration).append(semi); push(indent(sb.toString())); } - else { - String stmtOrDecl = pop(); - push(stmtOrDecl); - } + // otherwise, just leave it alone, 'statement' and 'localTypeDeclaration' + // can be multi-line statements that should already be indented. } /** @@ -475,7 +481,7 @@ */ @Override public void exitClassBody(ClassBodyContext ctx) { --tabCount; - String rbrace = pop(); + String rbrace = pop().trim(); rbrace = indent(rbrace); String classBodyDecl = ""; if (ctx.classBodyDeclaration() != null) { @@ -560,7 +566,6 @@ classBody = pop(); } String arguments = pop(); - arguments = indent(arguments); StringBuilder sb = new StringBuilder(arguments); if (classBody.length() > 0) { sb.append(' ').append(classBody); @@ -855,7 +860,6 @@ String classCreatorRest = pop(); String createdName = pop(); String nonWildcardTypeArguments = pop(); - nonWildcardTypeArguments = indent(nonWildcardTypeArguments); StringBuilder sb = new StringBuilder(); sb.append(nonWildcardTypeArguments).append(' ').append(createdName).append(classCreatorRest); push(sb); @@ -864,7 +868,6 @@ // second choice String end = pop(); // either arrayCreatorRest or classCreatorRest String createdName = pop(); - createdName = indent(createdName); StringBuilder sb = new StringBuilder(); sb.append(createdName).append(end); push(sb); @@ -1089,7 +1092,7 @@ if (enumBodyDeclarations.trim().length() > 1) { enumBodyDeclarations = trimFront(enumBodyDeclarations); } - sb.append(enumBodyDeclarations).append('\n'); + sb.append(enumBodyDeclarations); } rb = indent(rb); sb.append(rb).append('\n'); @@ -1122,16 +1125,11 @@ * ; */ @Override public void exitExplicitGenericInvocationSuffix(ExplicitGenericInvocationSuffixContext ctx) { - if (ctx.SUPER() != null) { - String suffix = pop(); - String super_ = pop(); // super keyword - push(super_ + ' ' + suffix); - } - else { - String arguments = pop(); - String identifier = pop(); - push(identifier + " " + arguments); - } + String second = pop(); // superSuffix or arguments + String first = pop(); // super keyword or identifier + StringBuilder sb = new StringBuilder(); + sb.append(first).append(' ').append(second); + push(sb); } @@ -1185,19 +1183,21 @@ // a few of the choices can be skipped since they should already be on the stack if (ctx.primary() != null) return; - if (ctx.methodCall() != null && ctx.expression() == null) + if (ctx.methodCall() != null && (ctx.expression() == null || ctx.expression().size() == 0)) { return; + } if (ctx.lambdaExpression() != null) return; - if (ctx.switchExpression() != null) + if (ctx.switchExpression() != null) { return; + } // things with NEW if (ctx.NEW() != null) { if (ctx.creator() != null) { // NEW creator - String creator = pop(); - String new_ = pop(); // new keyword + String creator = pop().trim(); + String new_ = pop().trim(); // new keyword StringBuilder sb = new StringBuilder(); sb.append(new_).append(' ').append(creator); push(sb); @@ -1281,12 +1281,15 @@ // | explicitGenericInvocation // ) if (ctx.identifier() != null || ctx.methodCall() != null || ctx.THIS() != null || ctx.explicitGenericInvocation() != null) { - String end = pop(); - String dot = pop(); // . bop - StringBuilder expression = new StringBuilder(pop()); - expression.append(dot); - expression.append(end); - push(expression); + String end = pop().trim(); + String dot = pop().trim(); // . bop + String expression = pop().trim(); + expression = indent(expression); + StringBuilder sb = new StringBuilder(); + sb.append(expression); + sb.append(dot); + sb.append(end); + push(sb); return; } if (ctx.NEW() != null) { @@ -1417,11 +1420,14 @@ // <assoc=right> expression // bop=('=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' | '>>=' | '>>>=' | '<<=' | '%=') // expression - String expression = pop(); - String bop = pop(); - StringBuilder sb = new StringBuilder(pop()); + String expression2 = pop().trim(); + String bop = pop().trim(); + String expression1 = pop().trim(); + expression1 = indent(expression1); + StringBuilder sb = new StringBuilder(); + sb.append(expression1); sb.append(padOperator(bop)); - sb.append(expression); + sb.append(expression2); push(sb); return; } @@ -2181,6 +2187,11 @@ push(semi); } // otherwise, block is already on the stack + else { + String block = pop(); + block = removeBlankLines(block, BOTH); + push(block); + } } /** @@ -2191,17 +2202,30 @@ * ; */ @Override public void exitMethodCall(MethodCallContext ctx) { - String rp = pop(); // ) - String expressionList = ctx.expressionList() == null ? "" : pop().trim(); - String lp = pop(); // ( - String start = pop(); // one of 'identifier', 'this', or 'super' - //start = removeBlankLines(start, BOTH); + String rp = pop().trim(); // ) + String expressionList = ctx.expressionList() == null ? "" : pop(); + long lines = expressionList.lines().count(); + String lp = pop().trim(); // ( + String start = pop().trim(); // one of 'identifier', 'this', or 'super' + start = indent(start); + StringBuilder sb = new StringBuilder(); - if (!expressionList.isEmpty()) { - rp = padParen(rp); - lp = padParen(lp); + sb.append(start); + if (lines > 1) { + sb.append(lp).append('\n'); + expressionList = removeBlankLines(expressionList, BOTH); + sb.append(indentAgain(expressionList)); + sb.append(indent(rp)); } - sb.append(start).append(lp).append(expressionList).append(rp); + else { + if (!expressionList.isEmpty()) { + lp = padParen(lp); + rp = padParen(rp); + } + sb.append(lp); + sb.append(expressionList.trim()); + sb.append(rp); + } push(sb); } @@ -2730,7 +2754,7 @@ } @Override public void enterStatement(StatementContext ctx) { - if (ctx.SWITCH() != null) { + if (ctx.SWITCH() != null || ctx.switchExpression() != null) { ++tabCount; } } @@ -2784,6 +2808,10 @@ --tabCount; formatSwitch(ctx); } + else if (ctx.switchExpression() != null) { + --tabCount; + formatSwitchExpression(ctx); + } else if (ctx.SYNCHRONIZED() != null) { formatSynchronized(ctx); } @@ -2934,7 +2962,7 @@ private void formatSwitch(StatementContext ctx) { // SWITCH parExpression '{' switchBlockStatementGroup* switchLabel* '}' - String rp = pop(); // } + String rp = pop().trim(); // } rp = indent(rp); String switchLabel = ""; if (ctx.switchLabel() != null && ctx.switchLabel().size() > 0) { @@ -2944,17 +2972,30 @@ String switchBlockStatementGroup = ""; if (ctx.switchBlockStatementGroup() != null && ctx.switchBlockStatementGroup().size() > 0) { int size = ctx.switchBlockStatementGroup().size(); - switchBlockStatementGroup = reverse(size, ""); + switchBlockStatementGroup = reverse(size, ""); } String lp = pop(); // { String parExpression = pop(); - String switch_ = pop(); // switch keyword + String switch_ = pop().trim(); // switch keyword switch_ = indent(switch_); StringBuilder sb = new StringBuilder(); - sb.append('\n').append(switch_).append(' ').append(parExpression).append(' ').append(lp).append('\n').append(switchBlockStatementGroup).append(switchLabel).append(rp).append('\n'); + sb.append(switch_).append(' ').append(parExpression).append(' ').append(lp).append('\n').append(switchBlockStatementGroup).append(switchLabel).append(rp).append('\n'); push(sb); } + private void formatSwitchExpression(StatementContext ctx) { + // switchExpression ';'? // Java17 + String semi = ""; + if (ctx.SEMI() != null) { + semi = pop().trim(); + } + String expression = pop(); + StringBuilder sb = new StringBuilder(); + sb.append(expression); + sb.append(semi); + push(sb); + } + private void formatSynchronized(StatementContext ctx) { // SYNCHRONIZED parExpression block String block = pop(); @@ -2971,9 +3012,9 @@ // RETURN expression? ';' // THROW expression ';' // YIELD expression ';' - String semi = pop(); //; + String semi = pop().trim(); //; String expression = ctx.expression() == null ? "" : pop().trim(); - String keyword = pop(); + String keyword = pop().trim(); keyword = indent(keyword); StringBuilder sb = new StringBuilder(); sb.append(keyword).append(' ').append(expression).append(semi); @@ -2985,7 +3026,7 @@ // CONTINUE identifier? ';' String semi = pop().trim(); String identifier = ctx.identifier() == null ? "" : " " + pop().trim(); - String keyword = pop(); + String keyword = pop().trim(); keyword = indent(keyword); StringBuilder sb = new StringBuilder(); sb.append(keyword).append(identifier).append(semi); @@ -2993,16 +3034,18 @@ } private void formatSemi(StatementContext ctx) { - // only these 3 statement choices are remaining with a semicolon + // only these 2 statement choices are remaining with a semicolon // SEMI // statementExpression=expression ';' - // switchExpression ';'? // Java17 String semi = pop().trim(); // ; String expression = ""; - if (ctx.expression() != null || ctx.switchExpression() != null) { - expression = pop().trim(); - expression = indent(expression); + if (ctx.expression() != null) { + expression = pop(); } + long lines = expression.lines().count(); + if (lines > 1) { + expression = getIndent() + expression.trim(); + } StringBuilder sb = new StringBuilder(); sb.append(expression).append(semi).append('\n'); push(sb); @@ -3052,8 +3095,16 @@ blockStatements = indentAgain(blockStatements); size = ctx.switchLabel().size(); String switchLabels = reverse(size, ""); + StringBuilder sb = new StringBuilder(); - sb.append(switchLabels).append(blockStatements).append('\n'); + sb.append(switchLabels); + if (!switchLabels.endsWith("\n")) { + sb.append('\n'); + } + sb.append(blockStatements); + if (!blockStatements.endsWith("\n")) { + sb.append('\n'); + } push(sb); } @@ -3069,21 +3120,25 @@ */ @Override public void exitSwitchExpression(SwitchExpressionContext ctx) { --tabCount; - String rb = pop(); // } + String rb = pop().trim(); // } rb = indent(rb); + String switchLabeledRule = ""; if (ctx.switchLabeledRule() != null) { int size = ctx.switchLabeledRule().size(); switchLabeledRule = reverse(size, ""); + if (!switchLabeledRule.endsWith("\n")) { + switchLabeledRule += '\n'; + } } String lb = pop(); // { String parExpression = pop(); String switch_ = pop(); // switch keyword switch_ = indent(switch_); + StringBuilder sb = new StringBuilder(); sb.append(switch_).append(' ').append(parExpression).append(' ').append(lb).append('\n').append(switchLabeledRule).append(rb).append('\n'); - String expression = indentAgain(sb.toString()); - push(expression); + push(sb); } @Override public void enterSwitchLabel(SwitchLabelContext ctx) { @@ -3104,20 +3159,20 @@ push(sb); } else { - String colon = pop(); + String colon = pop().trim(); String label = ""; if (ctx.typeType() != null) { - String identifier = pop(); - String typeType = pop(); + String identifier = pop().trim(); + String typeType = pop().trim(); label = new StringBuilder(typeType).append(' ').append(identifier).toString(); } else { - label = pop(); + label = pop().trim(); } - String case_ = pop(); + String case_ = pop().trim(); case_ = indent(case_); StringBuilder sb = new StringBuilder(); - sb.append(case_).append(' ').append(label).append(colon).append('\n'); + sb.append(case_).append(' ').append(label).append(colon); push(sb); } } @@ -3133,10 +3188,10 @@ */ @Override public void exitSwitchLabeledRule(SwitchLabeledRuleContext ctx) { if (ctx.CASE() != null) { - String switchRuleOutcome = pop(); - String operator = pop(); - String choice = pop(); - String case_ = pop(); + String switchRuleOutcome = pop().trim(); + String operator = pop().trim(); + String choice = pop().trim(); + String case_ = pop().trim(); case_ = indent(case_); StringBuilder sb = new StringBuilder(); sb.append(case_).append(' ').append(choice).append(padOperator(operator)).append(switchRuleOutcome).append('\n'); @@ -3143,12 +3198,12 @@ push(sb); } else { - String switchRuleOutcome = pop(); - String operator = pop(); - String default_ = pop(); + String switchRuleOutcome = pop().trim(); + String operator = pop().trim(); + String default_ = pop().trim(); default_ = indent(default_); StringBuilder sb = new StringBuilder(); - sb.append(default_).append(padOperator(operator)).append(switchRuleOutcome).append('\n'); + sb.append(default_).append(padOperator(operator)).append(switchRuleOutcome); push(sb); } } @@ -3162,7 +3217,7 @@ * ; */ @Override public void exitSwitchRuleOutcome(SwitchRuleOutcomeContext ctx) { - if (ctx.blockStatement() != null) { + if (ctx.blockStatement() != null && ctx.blockStatement().size() > 0) { String blockStatement = ""; if (ctx.blockStatement() != null) { int size = ctx.blockStatement().size(); @@ -3170,7 +3225,6 @@ } push(blockStatement.trim()); } - // otherwise, 'block' is already on the stack } @@ -3600,18 +3654,17 @@ } } + /** - * Trim the given string of leading and trailing whitespece, split it into - * lines, then add tabCount * tab whitespace to the start of each line, - * then return the combined lines. Note that there will NOT be a trailing new line. + * Split the given string into lines, trim each line, then add tabcount * tab + * whitespace to the start of each line and a new line at the end of each line. */ private String indent(String s) { - s = s.trim(); StringBuilder sb = new StringBuilder(); String[] lines = s.split("\n"); String indent = getIndent(); for (String line : lines) { - sb.append(indent).append(line).append('\n'); + sb.append(indent).append(line.trim()).append('\n'); } return trimEnd(sb); } @@ -3623,10 +3676,7 @@ StringBuilder sb = new StringBuilder(); String[] lines = s.split("\n"); for (String line : lines) { - sb.append(tab).append(line); - if (!line.endsWith("\n")) { - sb.append('\n'); - } + sb.append(tab).append(line).append('\n'); } return sb.toString(); } @@ -3644,18 +3694,23 @@ return s; // shouldn't happen } - /* - private String indentRBrace(String s) { - //s = s.trim(); - String start = s.substring(0, s.indexOf('}')); - String rbrace = s.substring(s.indexOf('}')); - if (!start.isEmpty()) { - start = indent(start); + /** + * Removes one tab from the beginning of each line in <code>s</code>. + */ + private String outdent(String s) { + StringBuilder sb = new StringBuilder(); + String[] lines = s.split("\n"); + for (String line : lines) { + if (line.startsWith(tab)) { + line = line.substring(tab.length()); + } + sb.append(line); + if (!line.endsWith("\n")) { + sb.append('\n'); + } } - rbrace = indent(rbrace); - return start + rbrace; + return sb.toString(); } - */ /** * Add blank lines to the end of the last item on the stack. Note that all This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dal...@us...> - 2022-08-02 22:45:39
|
Revision: 25589 http://sourceforge.net/p/jedit/svn/25589 Author: daleanson Date: 2022-08-02 22:45:37 +0000 (Tue, 02 Aug 2022) Log Message: ----------- Continuing fine tuning. Modified Paths: -------------- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java Modified: plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java =================================================================== --- plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-07-29 22:37:47 UTC (rev 25588) +++ plugins/Beauty/trunk/src/beauty/parsers/java/java/JavaParserBeautyListener.java 2022-08-02 22:45:37 UTC (rev 25589) @@ -10,7 +10,17 @@ import java.util.regex.*; /** - * Beautifier for Java 18 and below. + * Beautifier for Java 17 and below. + + Notes about indenting: + + Parent sets the indent level on entry + Child applies the indent level to itself + Parent adds the child + + Standard parent/child tree hierarchy. The leaf child will be a one liner. + + */ public class JavaParserBeautyListener extends JavaParserBaseListener { @@ -53,7 +63,7 @@ private int blankLinesBetweenImportGroups = 1; private int blankLinesAfterClassDeclaration = 1; private int blankLinesAfterClassBody = 2; - private int blankLinesBeforeMethods = 1; + private int blankLinesBeforeMethods = 2; private int blankLinesAfterMethods = 1; private boolean sortModifiers = true; private int collapseMultipleBlankLinesTo = 2; @@ -112,7 +122,7 @@ JavaLexer lexer = new JavaLexer( antlrInput ); CommonTokenStream tokens = new CommonTokenStream( lexer ); JavaParser javaParser = new JavaParser( tokens ); - //javaParser.setTrace(true); + javaParser.setTrace(true); // parse and beautify the buffer contents JavaParserBeautyListener listener = new JavaParserBeautyListener(16 * 1024, tokens); @@ -367,35 +377,35 @@ } @Override public void enterBlock(BlockContext ctx) { - ++tabCount; + ++tabCount; } /** - * block - * : '{' blockStatement* '}' - * ; - */ + * block + * : '{' blockStatement* '}' + * ; + */ @Override public void exitBlock(BlockContext ctx) { - String rb = trimFront(pop()); - StringBuilder blockStatements = new StringBuilder(); + --tabCount; + + String rb = pop(); + + String blockStatements = ""; if (ctx.blockStatement() != null) { int size = ctx.blockStatement().size(); - List<String> parts = reverse(size); - for (String part : parts) { - blockStatements.append(indent(part)); - } - //trimEnd(blockStatements); + blockStatements = reverse(size, ""); } + String lb = pop().trim(); - String lb = pop(); - --tabCount; - - rb = indentRBrace(rb); + // assemble the parts StringBuilder sb = new StringBuilder(); - if (brokenBracket) { - sb.append('\n'); + // TODO: broken brackets + sb.append(lb); + if (!blockStatements.isEmpty()) { + sb.append('\n'); + rb = indent(rb); } - sb.append(lb).append(blockStatements).append('\n').append(rb); + sb.append(blockStatements).append('\n').append(rb); push(sb); } @@ -406,16 +416,17 @@ * | localTypeDeclaration * ; */ - @Override public void exitBlockStatement(BlockStatementContext ctx) { + @Override public void exitBlockStatement(BlockStatementContext ctx) { if (ctx.SEMI() != null) { String semi = pop(); - String localVariableDeclaration = pop() + semi; - localVariableDeclaration = indent(localVariableDeclaration); - push(localVariableDeclaration); + String localVariableDeclaration = pop(); + StringBuilder sb = new StringBuilder(); + sb.append(localVariableDeclaration).append(semi); + push(indent(sb.toString())); } else { String stmtOrDecl = pop(); - push(indent(stmtOrDecl) + '\n'); + push(stmtOrDecl); } } @@ -454,44 +465,34 @@ } @Override public void enterClassBody(ClassBodyContext ctx) { - ++tabCount; + ++tabCount; } - - + /** * classBody * : '{' classBodyDeclaration* '}' * ; */ - @Override public void exitClassBody(ClassBodyContext ctx) { + @Override public void exitClassBody(ClassBodyContext ctx) { + --tabCount; String rbrace = pop(); - StringBuilder classBodyDecl = new StringBuilder(); + rbrace = indent(rbrace); + String classBodyDecl = ""; if (ctx.classBodyDeclaration() != null) { int size = ctx.classBodyDeclaration().size(); - List<String> parts = reverse(size); - for (String part : parts) { - classBodyDecl.append(indent(part)).append('\n'); - } - trimEnd(classBodyDecl); + classBodyDecl = reverse(size, "\n\n"); } - String lbrace = pop(); - - --tabCount; - + String lbrace = pop().trim(); + StringBuilder sb = new StringBuilder(); - - if (isWhitespace(classBodyDecl) || classBodyDecl.length() == 0) { - sb.append(lbrace.trim()).append(rbrace.trim()).append('\n'); - } - else { - sb.append(lbrace); - if (brokenBracket) { - sb.append('\n'); - } - sb.append(classBodyDecl).append('\n'); - rbrace = indentRBrace(rbrace); - sb.append(rbrace).append('\n'); - } + // TODO: fix this + //if (brokenBracket) { + // sb.append('\n'); + //} + sb.append(lbrace).append('\n'); + sb.append(classBodyDecl); + sb.append('\n'); + sb.append(rbrace); push(sb); } @@ -505,27 +506,44 @@ */ @Override public void exitClassBodyDeclaration(ClassBodyDeclarationContext ctx) { if (ctx.SEMI() != null) { - return; // only thing in the class body is a semicolon, and it's already on the stack + String semi = pop(); + semi = indent(semi); + push(semi); + return; } if (ctx.block() != null) { - StringBuilder block = new StringBuilder(pop()); - if (ctx.STATIC() != null) { - String static_ = pop(); // static keyword - block.insert(0, static_ + ' '); - } - push(block); - return; + String block = pop(); + StringBuilder sb = new StringBuilder(); + addBlankLines(sb, blankLinesBeforeMethods, START); + if (ctx.STATIC() != null) { + String static_ = pop(); // static keyword + static_ = indent(static_); + sb.append(static_).append(' '); + } + block = addBlankLines(block, blankLinesAfterMethods, END); + sb.append(block); + push(sb); + return; } else { - String memberDeclaration = pop(); + String memberDeclaration = pop().trim(); + StringBuilder sb = new StringBuilder(); - if (ctx.modifier() != null) { + addBlankLines(sb, blankLinesBeforeMethods, START); + String modifiers = ""; + if (ctx.modifier() != null && ctx.modifier().size() > 0) { int size = ctx.modifier().size(); - String mods = formatModifiers(size); - sb.append(mods.trim()).append(' '); + modifiers = formatModifiers(size); } - sb.append(memberDeclaration); + if (!modifiers.isEmpty()) { + modifiers = indent(modifiers); + sb.append(modifiers).append(' ').append(memberDeclaration); + } + else { + String indent = getIndent(); + sb.append(indent).append(memberDeclaration); + } push(sb); } } @@ -542,6 +560,7 @@ classBody = pop(); } String arguments = pop(); + arguments = indent(arguments); StringBuilder sb = new StringBuilder(arguments); if (classBody.length() > 0) { sb.append(' ').append(classBody); @@ -560,33 +579,35 @@ */ @Override public void exitClassDeclaration(ClassDeclarationContext ctx) { String classBody = pop(); - String permitsList = ""; + StringBuilder permitsList = new StringBuilder(); if (ctx.PERMITS() != null && ctx.typeList() != null) { String typeList = pop(); String permits_ = pop(); - permitsList = permits_ + ' ' + typeList; + permitsList.append(' ').append(permits_).append(' ').append(typeList); } - String implementsList = ""; + StringBuilder implementsList = new StringBuilder(); if (ctx.IMPLEMENTS() != null && ctx.typeList() != null) { String typeList = pop(); String implements_ = pop(); - implementsList = implements_ + ' ' + typeList; + implementsList.append(' ').append(implements_).append(' ').append(typeList); } - String extendsType = ""; + StringBuilder extendsType = new StringBuilder(); if (ctx.EXTENDS() != null && ctx.typeList() != null) { String typeType = pop(); String extends_ = pop(); - extendsType = extends_ + ' ' + typeType; + extendsType.append(' ').append(extends_).append(' ').append(typeType); } - String typeParameters = ""; + StringBuilder typeParameters = new StringBuilder(); if (ctx.typeParameters() != null) { - typeParameters = pop(); + String params = pop(); + typeParameters.append(' ').append(params); } String identifier = pop(); String class_ = pop(); // class keyword + class_ = indent(class_); StringBuilder classDecl = new StringBuilder(); - classDecl.append(class_).append(' ').append(identifier).append(' ').append(typeParameters).append(' ').append(extendsType).append(implementsList).append(permitsList).append(classBody); + classDecl.append(class_).append(' ').append(identifier).append(typeParameters).append(extendsType).append(implementsList).append(permitsList).append(' ').append(classBody); push(classDecl); } @@ -670,6 +691,15 @@ String dot = pop(); // . classOrInterfaceType = pop() + dot; } + if (!classOrInterfaceType.isEmpty()) { + classOrInterfaceType = indent(classOrInterfaceType); + } + else if (!annotations.isEmpty()) { + annotations = indent(annotations); + } + else { + identifier = indent(identifier); + } StringBuilder sb = new StringBuilder(); sb.append(classOrInterfaceType).append(annotations).append(' ').append(identifier).append(typeArguments); push(sb); @@ -724,6 +754,7 @@ int size = ctx.constantDeclarator().size(); String constantDeclarator = reverse(size * 2 - 1, " ", 2); String typeType = pop(); + typeType = indent(typeType); StringBuilder sb = new StringBuilder(); sb.append(typeType).append(' ').append(constantDeclarator).append(semi); push(sb); @@ -743,6 +774,7 @@ brackets = reverse(size, ""); } String identifier = stack.pop(); + identifier = indent(identifier); StringBuilder sb = new StringBuilder(); sb.append(identifier).append(brackets).append(padOperator(equals)).append(variableInitializer); push(sb); @@ -754,17 +786,18 @@ * ; */ @Override public void exitConstructorDeclaration(ConstructorDeclarationContext ctx) { - String block = pop(); - StringBuilder throwsList = new StringBuilder();; + String block = pop(); + StringBuilder throwsList = new StringBuilder(); if (ctx.THROWS() != null) { - String qualifiedNameList = pop(); + String qualifiedNameList = pop().trim(); String throws_ = pop(); // throws keyword throwsList.append(throws_).append(' ').append(qualifiedNameList); } - String formalParameters = pop(); - String identifier = pop(); + String formalParameters = pop().trim(); + String identifier = pop().trim(); + identifier = indent(identifier); StringBuilder sb = new StringBuilder(); - sb.append(identifier).append(' ').append(formalParameters).append(' ').append(throwsList).append(block); + sb.append(identifier).append(formalParameters).append(' ').append(throwsList).append(block); push(sb); } @@ -801,11 +834,13 @@ maybeType = ""; } String identifier = pop(); + identifier = indent(identifier); StringBuilder sb = new StringBuilder(); sb.append(identifier).append(maybeType).append(backHalf); push(sb); } // otherwise, nothing to do as primitiveType should already be on the stack + // TODO: but is it indented? } /** @@ -820,6 +855,7 @@ String classCreatorRest = pop(); String createdName = pop(); String nonWildcardTypeArguments = pop(); + nonWildcardTypeArguments = indent(nonWildcardTypeArguments); StringBuilder sb = new StringBuilder(); sb.append(nonWildcardTypeArguments).append(' ').append(createdName).append(classCreatorRest); push(sb); @@ -828,6 +864,7 @@ // second choice String end = pop(); // either arrayCreatorRest or classCreatorRest String createdName = pop(); + createdName = indent(createdName); StringBuilder sb = new StringBuilder(); sb.append(createdName).append(end); push(sb); @@ -842,6 +879,7 @@ @Override public void exitDefaultValue(DefaultValueContext ctx) { String elementValue = pop(); String default_ = pop(); + default_ = indent(default_); StringBuilder sb = new StringBuilder(); sb.append(default_).append(' ').append(elementValue); push(sb); @@ -862,6 +900,7 @@ * elementValueArrayInitializer * : '{' (elementValue (',' elementValue)*)? (',')? '}' * ; + * TODO: wrap long lines? */ @Override public void exitElementValueArrayInitializer(ElementValueArrayInitializerContext ctx) { String rbrace = pop(); @@ -941,13 +980,13 @@ String classBodyDeclaration = ""; if (ctx.classBodyDeclaration() != null) { int size = ctx.classBodyDeclaration().size(); - classBodyDeclaration = reverse(size, "\n"); + classBodyDeclaration = reverse(size, ""); } - String semi = pop(); // ; + String semi = pop().trim(); // ; StringBuilder sb = new StringBuilder(); - sb.append(semi); + sb.append(semi).append('\n'); if (!isWhitespace(classBodyDeclaration)) { - sb.append('\n'); + sb.append("\n"); sb.append(classBodyDeclaration); } push(sb); @@ -974,6 +1013,12 @@ int size = ctx.annotation().size(); annotations = reverse(size, " "); } + if (!annotations.isEmpty()) { + annotations = indent(annotations); + } + else { + identifier = indent(identifier); + } StringBuilder sb = new StringBuilder(); sb.append(annotations).append(identifier).append(' '); if (arguments.length() > 0) { @@ -990,10 +1035,27 @@ */ @Override public void exitEnumConstants(EnumConstantsContext ctx) { int size = ctx.enumConstant().size(); - String enumConstants = reverse(size * 2 - 1, " ", 2); + if (ctx.COMMA() != null) { + size += ctx.COMMA().size(); + } + StringBuilder sb = new StringBuilder(); + List<String> constants = reverse(size); + for (int i = 0; i < size; i++) { + String constant = constants.get(i).trim(); + sb.append(constant); + if (constant.equals(",")) { + sb.append(' '); + } + } + String enumConstants = sb.toString(); + enumConstants = trimEnd(enumConstants); + enumConstants = indent(enumConstants); push(enumConstants); } + @Override public void enterEnumDeclaration(EnumDeclarationContext ctx) { + ++tabCount; + } /** * enumDeclaration @@ -1001,10 +1063,11 @@ * ; */ @Override public void exitEnumDeclaration(EnumDeclarationContext ctx) { + --tabCount; String rb = pop(); // } String enumBodyDeclarations = ctx.enumBodyDeclarations() == null ? "" : pop(); - String comma = ctx.COMMA() == null ? "" : ", "; - String enumConstants = ctx.enumConstants() == null ? "" : pop().trim(); + String comma = ctx.COMMA() == null ? "" : pop(); + String enumConstants = ctx.enumConstants() == null ? "" : pop(); String lb = pop(); // { String implements_ = ""; if (ctx.IMPLEMENTS() != null && ctx.typeList() != null) { @@ -1014,17 +1077,22 @@ } String identifier = pop(); String enum_ = pop(); // enum keyword + enum_ = indent(enum_); + StringBuilder sb = new StringBuilder(); sb.append(enum_).append(' ').append(identifier).append(' ').append(implements_).append(lb).append('\n'); if (!enumConstants.isEmpty() || !comma.isEmpty() || !enumBodyDeclarations.isEmpty()) { - sb.append(trimEnd(indent(enumConstants))).append(comma); + sb.append(enumConstants); + if (!comma.isEmpty()) { + sb.append(comma).append(' '); + } if (enumBodyDeclarations.trim().length() > 1) { - enumBodyDeclarations = indent(enumBodyDeclarations); enumBodyDeclarations = trimFront(enumBodyDeclarations); } - sb.append(enumBodyDeclarations); + sb.append(enumBodyDeclarations).append('\n'); } - sb.append(rb); + rb = indent(rb); + sb.append(rb).append('\n'); push(sb); } @@ -1041,6 +1109,7 @@ @Override public void exitExplicitGenericInvocation(ExplicitGenericInvocationContext ctx) { String suffix = pop(); String args = pop(); + args = indent(args); StringBuilder sb = new StringBuilder(); sb.append(args).append(' ').append(suffix); push(sb); @@ -1068,6 +1137,7 @@ /* * Yes, this is ugly. + * These should all be one-liners. * * expression * : primary @@ -1390,10 +1460,11 @@ */ @Override public void exitFieldDeclaration(FieldDeclarationContext ctx) { String semi = pop(); // semicolon - String variableDeclarators = pop(); + String variableDeclarators = pop().trim(); String typeType = stack.pop(); + typeType = indent(typeType); StringBuilder sb = new StringBuilder(); - sb.append(typeType).append(' ').append(variableDeclarators).append(semi); + sb.append(typeType).append(' ').append(variableDeclarators).append(semi).append('\n'); push(sb); } @@ -1405,6 +1476,7 @@ @Override public void exitFinallyBlock(FinallyBlockContext ctx) { String block = pop(); String finally_ = pop(); // finally keyword + finally_ = indent(finally_); push(finally_ + ' ' + block); } @@ -1528,9 +1600,12 @@ * ; */ @Override public void exitGenericConstructorDeclaration(GenericConstructorDeclarationContext ctx) { - String decl = pop(); - String typeParameters = pop(); - push(typeParameters + " " + decl); + String decl = pop().trim(); + String typeParameters = pop().trim(); + typeParameters = indent(typeParameters); + StringBuilder sb = new StringBuilder(); + sb.append(typeParameters).append(' ').append(decl); + push(sb); } /** @@ -1546,6 +1621,7 @@ int size = ctx.interfaceMethodModifier().size(); modifiers = formatModifiers(size).trim(); } + modifiers = indent(modifiers); StringBuilder sb = new StringBuilder(); sb.append(modifiers).append(' ').append(typeParameters).append(' ').append(decl); push(sb); @@ -1560,6 +1636,7 @@ @Override public void exitGenericMethodDeclaration(GenericMethodDeclarationContext ctx) { String method = pop(); String typeParameters = pop(); + typeParameters = indent(typeParameters); StringBuilder sb = new StringBuilder(); sb.append(typeParameters).append(' ').append(method); push(sb); @@ -1670,6 +1747,7 @@ static_ = pop() + ' '; // static keyword } String import_ = pop(); // import keyword + import_ = indent(import_); StringBuilder importDecl = new StringBuilder(); importDecl.append(import_).append(' ').append(static_).append(qualifiedName).append(dotstar).append(semi); push(importDecl); @@ -1684,6 +1762,7 @@ String classCreatorRest = pop(); String args = ctx.nonWildcardTypeArgumentsOrDiamond() == null ? " " : pop(); String identifier = pop(); + // TODO: indent? StringBuilder sb = new StringBuilder(); sb.append(identifier).append(args).append(classCreatorRest); push(sb); @@ -1701,11 +1780,9 @@ // Nothing to do here, one of the choices should already be on the stack. } - @Override public void enterInterfaceBody(InterfaceBodyContext ctx) { - ++tabCount; - } - + ++tabCount; + } /** * interfaceBody * : '{' interfaceBodyDeclaration* '}' @@ -1712,16 +1789,16 @@ * ; */ @Override public void exitInterfaceBody(InterfaceBodyContext ctx) { + --tabCount; String rb = pop(); // } - rb = removeBlankLines(rb, START); String body = ""; if (ctx.interfaceBodyDeclaration() != null && ctx.interfaceBodyDeclaration().size() > 0) { body = reverse(ctx.interfaceBodyDeclaration().size(), ""); - body = indent(body); body = removeBlankLines(body, BOTH); } + // TODO: what? why add blank lines after the left bracket? should be the right? addBlankLines(blankLinesAfterClassDeclaration); // added to left bracket String lb = pop(); // { @@ -1732,10 +1809,8 @@ sb.append(lb); sb.append(body); - --tabCount; - trimEnd(sb); - rb = indentRBrace(rb); + rb = indent(rb); if (!body.isEmpty()) { sb.append('\n'); } @@ -1761,7 +1836,11 @@ sb.append(modifiers).append(' ').append(decl); push(sb); } - // the semicolon choice is already on the stack + else { + String semi = pop(); + semi = indent(semi); + push(semi); + } } @@ -1852,6 +1931,7 @@ int size = ctx.interfaceMethodModifier().size(); modifiers = formatModifiers(size).trim(); } + modifiers = indent(modifiers); StringBuilder sb = new StringBuilder(); sb.append(modifiers).append(' ').append(decl); push(sb); @@ -2014,7 +2094,10 @@ */ @Override public void exitLocalTypeDeclaration(LocalTypeDeclarationContext ctx) { if (ctx.SEMI() != null) { - return; // Just a semicolon in the type declaration + String semi = pop(); + semi = indent(semi); + push(semi); + return; } String declaration = pop(); String modifiers = ""; @@ -2022,6 +2105,7 @@ int size = ctx.classOrInterfaceModifier().size(); modifiers = formatModifiers(size).trim(); } + modifiers = indent(modifiers); StringBuilder sb = new StringBuilder(); sb.append(modifiers).append(' ').append(declaration); push(sb); @@ -2043,17 +2127,26 @@ type.append(var_).append(' ').append(identifier).append(equals).append(expression); } else { - String variableDecls = pop(); + String variableDecls = pop().trim(); String typeType = pop(); type.append(typeType).append(' ').append(variableDecls); } + + String modifiers = ""; StringBuilder variableModifiers = new StringBuilder(); if (ctx.variableModifier() != null) { int size = ctx.variableModifier().size(); - variableModifiers.append(formatModifiers(size).trim()).append(' '); + modifiers = formatModifiers(size); } - variableModifiers.append(type); - push(variableModifiers); + modifiers = indent(modifiers); + + StringBuilder sb = new StringBuilder(); + sb.append(modifiers); + if (!modifiers.isEmpty()) { + sb.append(' '); + } + sb.append(type); + push(sb); } @@ -2082,7 +2175,12 @@ * ; */ @Override public void exitMethodBody(MethodBodyContext ctx) { - // Nothing to do here, one of the choices should already be on the stack. + if (ctx.SEMI() != null) { + String semi = pop(); + semi = indent(semi); + push(semi); + } + // otherwise, block is already on the stack } /** @@ -2094,9 +2192,10 @@ */ @Override public void exitMethodCall(MethodCallContext ctx) { String rp = pop(); // ) - String expressionList = ctx.expressionList() == null ? "" : pop(); + String expressionList = ctx.expressionList() == null ? "" : pop().trim(); String lp = pop(); // ( String start = pop(); // one of 'identifier', 'this', or 'super' + //start = removeBlankLines(start, BOTH); StringBuilder sb = new StringBuilder(); if (!expressionList.isEmpty()) { rp = padParen(rp); @@ -2127,11 +2226,12 @@ int size = ctx.RBRACK().size() * 2; // * 2 for LBRACK brackets = reverse(size, ""); } - String formalParameters = pop(); - String identifier = pop(); - String typeOrVoid = pop(); + String formalParameters = pop().trim(); + String identifier = pop().trim(); + String typeOrVoid = pop().trim(); + typeOrVoid = indent(typeOrVoid); StringBuilder method = new StringBuilder(); - method.append(typeOrVoid).append(' ').append(identifier).append(' ').append(formalParameters).append(' ').append(brackets).append(throwsList).append(methodBody); + method.append(typeOrVoid).append(' ').append(identifier).append(formalParameters).append(' ').append(brackets).append(throwsList).append(methodBody); push(method); } @@ -2148,6 +2248,9 @@ // Nothing to do here, one of the choices should aready be on the stack. } + @Override public void enterModuleBody(ModuleBodyContext ctx) { + ++tabCount; + } /** @@ -2155,8 +2258,10 @@ * : '{' moduleDirective* '}' * ; */ - @Override public void exitModuleBody(ModuleBodyContext ctx) { + @Override public void exitModuleBody(ModuleBodyContext ctx) { + --tabCount; String rbrace = pop(); + rbrace = indent(rbrace); StringBuilder moduleDirectives = new StringBuilder(); if (ctx.moduleDirective() != null) { int size = ctx.moduleDirective().size(); @@ -2168,7 +2273,7 @@ String lbrace = pop() + '\n'; StringBuilder moduleBody = new StringBuilder(); moduleBody.append(lbrace); - moduleBody.append(indent(moduleDirectives.toString())); + moduleBody.append(moduleDirectives); moduleBody.append(rbrace); push(moduleBody); } @@ -2265,7 +2370,7 @@ moduleDirective.append(provides_).append(' ').append(qualifiedName).append(' ').append(with_).append(' ').append(qualifiedName2); } moduleDirective.append(semi); - push(moduleDirective); + push(indent(moduleDirective.toString())); } /** @@ -2469,13 +2574,20 @@ push(sb); } + @Override public void enterRecordBody(RecordBodyContext ctx) { + ++tabCount; + } + + /** * recordBody * : '{' classBodyDeclaration* '}' * ; */ - @Override public void exitRecordBody(RecordBodyContext ctx) { + @Override public void exitRecordBody(RecordBodyContext ctx) { + --tabCount; String rb = pop(); // } + rb = indent(rb); String classBodyDeclaration = ""; if (ctx.classBodyDeclaration() != null) { int size = ctx.classBodyDeclaration().size(); @@ -2483,8 +2595,7 @@ } String lb = pop(); // { StringBuilder sb = new StringBuilder(); - // TODO: adjust brackets - sb.append(lb).append('\n').append(indent(classBodyDeclaration)).append(rb).append('\n'); + sb.append(lb).append('\n').append(classBodyDeclaration).append(rb).append('\n'); push(sb); } @@ -2618,6 +2729,11 @@ push(reverse(size * 2 - 1, " ", 2)); } + @Override public void enterStatement(StatementContext ctx) { + if (ctx.SWITCH() != null) { + ++tabCount; + } + } /** * statement @@ -2643,6 +2759,9 @@ * ; */ @Override public void exitStatement(StatementContext ctx) { + if (ctx.block() != null) { + return; // already on the stack + } if (ctx.ASSERT() != null) { formatAssert(ctx); } @@ -2662,6 +2781,7 @@ formatTry(ctx); } else if (ctx.SWITCH() != null) { + --tabCount; formatSwitch(ctx); } else if (ctx.SYNCHRONIZED() != null) { @@ -2695,7 +2815,7 @@ String assert_ = pop(); // assert keyword StringBuilder sb = new StringBuilder(); sb.append(assert_).append(' ').append(expression).append(padOperator(colon)).append(expression2).append(semi); - push(sb); + push(indent(sb.toString())); } private void formatIf(StatementContext ctx) { @@ -2703,34 +2823,19 @@ StringBuilder elseStatement = new StringBuilder(); if (ctx.ELSE() != null) { String es = pop(); - if (!es.trim().startsWith("{")) { - ++tabCount; - elseStatement.append(" {\n").append(indent(es)); - --tabCount; - elseStatement.append("\n}\n"); - } - else { - elseStatement.append(es); - if (!es.endsWith("\n")) { - elseStatement.append('\n'); - } - } - String else_ = pop(); // else keyword - elseStatement.insert(0, ' '); - elseStatement.insert(0, else_); + String else_ = indent(pop()); // else keyword + elseStatement.append('\n'); + elseStatement.append(else_); + elseStatement.append(es); } + String ifStatement = pop(); - if (!ifStatement.trim().startsWith("{")) { - ++tabCount; - ifStatement = " {\n" + indent(ifStatement); - --tabCount; - ifStatement += "\n}"; - } - String parExpression = pop(); String if_ = pop(); // if keyword + StringBuilder sb = new StringBuilder(); - sb.append(if_).append(' ').append(parExpression).append(' ').append(ifStatement).append(elseStatement); + sb.append(indent(if_)).append(' ').append(parExpression).append(' '); + sb.append(ifStatement).append(elseStatement); push(sb); } @@ -2737,20 +2842,21 @@ private void formatFor(StatementContext ctx) { // FOR '(' forControl ')' statement String statement = pop(); - // always require brackets - // TODO: what's the check for the statement starting with 'if'? - if (!statement.startsWith("{") && !statement.startsWith("if")) { - ++tabCount; - statement = " {\n" + indent(statement); - --tabCount; + // TODO: always require brackets + /* + if (!statement.startsWith("{")) { + statement = " {\n" + tab + statement.trim(); statement += "\n}\n"; } + */ + String rp = pop(); // ) String forControl = pop(); String lp = pop(); // ( - String for_ = pop(); // for keyword + String for_ = indent(pop()); // for keyword + StringBuilder sb = new StringBuilder(); - sb.append(for_).append(' ').append(padParen(lp)).append(forControl).append(' ').append(padParen(rp)).append(statement); + sb.append(for_).append(' ').append(padParen(lp)).append(forControl).append(' ').append(padParen(rp)).append(' ').append(statement); push(sb); } @@ -2759,6 +2865,7 @@ String statement = pop(); String parExpression = pop().trim(); String while_ = pop(); // while keyword + while_ = indent(while_); StringBuilder sb = new StringBuilder(); sb.append(while_).append(' ').append(parExpression).append(' ').append(statement); push(sb); @@ -2770,6 +2877,8 @@ String parExpression = pop(); String while_ = pop(); // while keyword String statement = pop(); + // TODO: always require brackets + /* if (!statement.startsWith("{")) { ++tabCount; statement = " {\n" + indent(statement); @@ -2776,7 +2885,9 @@ --tabCount; statement += "\n}"; } + */ String do_ = pop(); // do keyword + do_ = indent(do_); StringBuilder sb = new StringBuilder(); sb.append(do_).append(' ').append(statement).append(' ').append(while_).append(' ').append(parExpression).append(semi); push(sb); @@ -2796,6 +2907,7 @@ String block = pop(); String spec = pop(); String try_ = pop(); // try keyword + try_ = indent(try_); StringBuilder sb = new StringBuilder(); sb.append(try_).append(' ').append(spec).append(block).append(catchClause).append(finallyBlock); push(sb); @@ -2813,6 +2925,7 @@ } String block = pop(); String try_ = pop(); // try keyword + try_ = indent(try_); StringBuilder sb = new StringBuilder(); sb.append(try_).append(' ').append(block).append(catchClause).append(finallyBlock); push(sb); @@ -2822,21 +2935,23 @@ private void formatSwitch(StatementContext ctx) { // SWITCH parExpression '{' switchBlockStatementGroup* switchLabel* '}' String rp = pop(); // } + rp = indent(rp); String switchLabel = ""; - if (ctx.switchLabel() != null) { + if (ctx.switchLabel() != null && ctx.switchLabel().size() > 0) { int size = ctx.switchLabel().size(); - switchLabel = reverse(size, " "); + switchLabel = reverse(size, ""); } String switchBlockStatementGroup = ""; - if (ctx.switchBlockStatementGroup() != null) { + if (ctx.switchBlockStatementGroup() != null && ctx.switchBlockStatementGroup().size() > 0) { int size = ctx.switchBlockStatementGroup().size(); - switchBlockStatementGroup = reverse(size, " "); + switchBlockStatementGroup = reverse(size, ""); } String lp = pop(); // { String parExpression = pop(); String switch_ = pop(); // switch keyword + switch_ = indent(switch_); StringBuilder sb = new StringBuilder(); - sb.append(switch_).append(' ').append(parExpression).append(lp).append('\n').append(switchBlockStatementGroup).append(switchLabel).append('\n').append(rp); + sb.append('\n').append(switch_).append(' ').append(parExpression).append(' ').append(lp).append('\n').append(switchBlockStatementGroup).append(switchLabel).append(rp).append('\n'); push(sb); } @@ -2845,6 +2960,7 @@ String block = pop(); String parExpression = pop(); String synchronized_ = pop(); // synchronized keyword + synchronized_ = indent(synchronized_); StringBuilder sb = new StringBuilder(); sb.append(synchronized_).append(' ').append(parExpression).append(block); push(sb); @@ -2851,38 +2967,46 @@ } private void formatReturnThrowYield(StatementContext ctx) { - // these 3 are pretty much the same - // RETURN expression? ';' - // THROW expression ';' - // YIELD expression ';' - String semi = pop(); //; - String expression = ctx.expression() == null ? "" : pop(); - String keyword = pop(); - StringBuilder sb = new StringBuilder(); - sb.append(keyword).append(' ').append(expression).append(semi); - push(sb); + // these 3 are pretty much the same + // RETURN expression? ';' + // THROW expression ';' + // YIELD expression ';' + String semi = pop(); //; + String expression = ctx.expression() == null ? "" : pop().trim(); + String keyword = pop(); + keyword = indent(keyword); + StringBuilder sb = new StringBuilder(); + sb.append(keyword).append(' ').append(expression).append(semi); + push(sb); } private void formatBreakOrContinue(StatementContext ctx) { // BREAK identifier? ';' // CONTINUE identifier? ';' - String semi = pop(); //; - String identifier = ctx.identifier() == null ? "" : pop(); + String semi = pop().trim(); + String identifier = ctx.identifier() == null ? "" : " " + pop().trim(); String keyword = pop(); + keyword = indent(keyword); StringBuilder sb = new StringBuilder(); - sb.append(keyword).append(' ').append(identifier).append(semi); + sb.append(keyword).append(identifier).append(semi); push(sb); } private void formatSemi(StatementContext ctx) { - // only these 2 statement choices are remaining with a semicolon + // only these 3 statement choices are remaining with a semicolon + // SEMI // statementExpression=expression ';' - // switchExpression ';'? // Java17 - String semi = pop(); // ; - String expression = pop(); + // switchExpression ';'? // Java17 + String semi = pop().trim(); // ; + String expression = ""; + if (ctx.expression() != null || ctx.switchExpression() != null) { + expression = pop().trim(); + expression = indent(expression); + } StringBuilder sb = new StringBuilder(); - sb.append(expression).append(semi); + sb.append(expression).append(semi).append('\n'); push(sb); + } private void formatColon(StatementContext ctx) { @@ -2891,6 +3015,7 @@ String statement = pop(); String colon = pop(); // : String identifier = pop(); + identifier = indent(identifier); StringBuilder sb = new StringBuilder(); sb.append(identifier).append(padOperator(colon)).append(statement); push(sb); @@ -2924,13 +3049,18 @@ @Override public void exitSwitchBlockStatementGroup(SwitchBlockStatementGroupContext ctx) { int size = ctx.blockStatement().size(); String blockStatements = reverse(size, ""); + blockStatements = indentAgain(blockStatements); size = ctx.switchLabel().size(); String switchLabels = reverse(size, ""); StringBuilder sb = new StringBuilder(); - sb.append(switchLabels).append(blockStatements); + sb.append(switchLabels).append(blockStatements).append('\n'); push(sb); } + @Override public void enterSwitchExpression(SwitchExpressionContext ctx) { + ++tabCount; + } + /** * // Java17 * switchExpression @@ -2937,21 +3067,27 @@ * : SWITCH parExpression '{' switchLabeledRule* '}' * ; */ - @Override public void exitSwitchExpression(SwitchExpressionContext ctx) { + @Override public void exitSwitchExpression(SwitchExpressionContext ctx) { + --tabCount; String rb = pop(); // } + rb = indent(rb); String switchLabeledRule = ""; if (ctx.switchLabeledRule() != null) { int size = ctx.switchLabeledRule().size(); - switchLabeledRule = reverse(size, " "); + switchLabeledRule = reverse(size, ""); } String lb = pop(); // { String parExpression = pop(); String switch_ = pop(); // switch keyword + switch_ = indent(switch_); StringBuilder sb = new StringBuilder(); - sb.append(switch_).append(' ').append(parExpression).append(lb).append('\n').append(switchLabeledRule).append('\n').append(rb); - push(sb); + sb.append(switch_).append(' ').append(parExpression).append(' ').append(lb).append('\n').append(switchLabeledRule).append(rb).append('\n'); + String expression = indentAgain(sb.toString()); + push(expression); } + @Override public void enterSwitchLabel(SwitchLabelContext ctx) { + } /** * switchLabel * : CASE (constantExpression=expression | enumConstantName=IDENTIFIER | typeType varName=identifier) ':' @@ -2958,26 +3094,30 @@ * | DEFAULT ':' * ; */ - @Override public void exitSwitchLabel(SwitchLabelContext ctx) { + @Override public void exitSwitchLabel(SwitchLabelContext ctx) { if (ctx.DEFAULT() != null) { - String colon = pop(); // : + String colon = pop(); String default_ = pop(); // default keyword - push(default_ + colon); + default_ = indent(default_); + StringBuilder sb = new StringBuilder(); + sb.append(default_).append(colon).append('\n'); + push(sb); } else { - String colon = pop(); // : + String colon = pop(); String label = ""; if (ctx.typeType() != null) { String identifier = pop(); String typeType = pop(); - label = typeType + " " + identifier; + label = new StringBuilder(typeType).append(' ').append(identifier).toString(); } else { label = pop(); } String case_ = pop(); + case_ = indent(case_); StringBuilder sb = new StringBuilder(); - sb.append(case_).append(' ').append(label).append(colon); + sb.append(case_).append(' ').append(label).append(colon).append('\n'); push(sb); } } @@ -2996,17 +3136,19 @@ String switchRuleOutcome = pop(); String operator = pop(); String choice = pop(); - String case_ = pop(); // case keyword + String case_ = pop(); + case_ = indent(case_); StringBuilder sb = new StringBuilder(); - sb.append(case_).append(' ').append(choice).append(padOperator(operator)).append(switchRuleOutcome); + sb.append(case_).append(' ').append(choice).append(padOperator(operator)).append(switchRuleOutcome).append('\n'); push(sb); } else { String switchRuleOutcome = pop(); String operator = pop(); - String default_ = pop(); // default keyword + String default_ = pop(); + default_ = indent(default_); StringBuilder sb = new StringBuilder(); - sb.append(default_).append(padOperator(operator)).append(switchRuleOutcome); + sb.append(default_).append(padOperator(operator)).append(switchRuleOutcome).append('\n'); push(sb); } } @@ -3026,7 +3168,7 @@ int size = ctx.blockStatement().size(); blockStatement = reverse(size, " "); } - push(blockStatement); + push(blockStatement.trim()); } // otherwise, 'block' is already on the stack } @@ -3052,6 +3194,7 @@ int size = ctx.annotation().size(); annotation = reverse(size, " "); } + annotation = indent(annotation); StringBuilder sb = new StringBuilder(); sb.append(annotation).append(padOperator(q)).append(typeType); push(sb); @@ -3254,11 +3397,11 @@ String variableInitializer = ""; String equals = ""; if (ctx.variableInitializer() != null && ctx.ASSIGN() != null) { - variableInitializer = pop(); - equals = padOperator(pop()); + variableInitializer = pop().trim(); + equals = padOperator(pop().trim()); } StringBuilder variableDecl = new StringBuilder(); - variableDecl.append(pop()); // variableDeclaratorId + variableDecl.append(pop().trim()); // variableDeclaratorId variableDecl.append(padOperator(equals)); variableDecl.append(variableInitializer.trim()); push(variableDecl); @@ -3279,7 +3422,7 @@ variableDeclId.append(part); } } - variableDeclId.insert(0, pop()); // identifier + variableDeclId.insert(0, pop().trim()); // identifier push(variableDeclId); } @@ -3426,26 +3569,21 @@ private String getIndent() { StringBuilder sb = new StringBuilder(); for ( int i = 0; i < tabCount; i++ ) { - sb.insert(0, tab ); + sb.append( tab ); } return sb.toString(); } /** - * Removes one indent from each line in the given string. + * @return The indent in front of the given string. */ - private String outdent(String s) { + private String getIndent(String s) { + + String t = new String(s); StringBuilder sb = new StringBuilder(); - String[] lines = s.split("\n"); - String indent = getIndent(); - for (String line : lines) { - if (line.startsWith(indent)) { - line = line.substring(indent.length()); - } - sb.append(line); - if (!line.endsWith("\n")) { - sb.append('\n'); - } + while (t.length() > tab.length() && t.startsWith(tab)) { + sb.append(tab); + t = t.substring(tab.length()); } return sb.toString(); } @@ -3463,32 +3601,19 @@ } /** - * Split the given string into lines and indent each line to - * the current tab count. + * Trim the given string of leading and trailing whitespece, split it into + * lines, then add tabCount * tab whitespace to the start of each line, + * then return the combined lines. Note that there will NOT be a trailing new line. */ private String indent(String s) { + s = s.trim(); StringBuilder sb = new StringBuilder(); String[] lines = s.split("\n"); String indent = getIndent(); for (String line : lines) { - if (indent.isEmpty() || !line.startsWith(indent)) { - line = line.trim(); - if (line.startsWith("*")) { - // assume it's a comment line - // TODO: verify this is always true - line = new StringBuilder(indent).append(' ').append(line).toString(); - } - else if (!"".equals(line)) { - line = new StringBuilder(indent).append(line).toString(); - } - } - sb.append(line); - if (!line.endsWith("\n")) { - sb.append('\n'); - } + sb.append(indent).append(line).append('\n'); } - sb.deleteCharAt(sb.length() - 1); // delete the last \n - return sb.toString(); + return trimEnd(sb); } /** @@ -3507,7 +3632,21 @@ } private String indentRBrace(String s) { - s = s.trim(); + if (s.indexOf('}') > -1) { + StringBuilder sb = new StringBuilder(); + for ( int i = 0; i < tabCount - 1; i++ ) { + sb.append( tab ); + } + s = s.trim(); + sb.append(s); + return sb.toString(); + } + return s; // shouldn't happen + } + + /* + private String indentRBrace(String s) { + //s = s.trim(); String start = s.substring(0, s.indexOf('}')); String rbrace = s.substring(s.indexOf('}')); if (!start.isEmpty()) { @@ -3516,6 +3655,7 @@ rbrace = indent(rbrace); return start + rbrace; } + */ /** * Add blank lines to the end of the last item on the stack. Note that all @@ -3538,6 +3678,43 @@ return false; } + private String addBlankLines(StringBuilder sb, int howMany, int whichEnd) { + return addBlankLines(sb.toString(), howMany, whichEnd); + } + + private String addBlankLines(String s, int howMany, int whichEnd) { + if (s == null || s.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < howMany; i++) { + sb.append('\n'); + } + return sb.toString(); + } + + StringBuilder lines = new StringBuilder(); + for (int i = 0; i < howMany; i++) { + lines.append('\n'); + } + + StringBuilder sb = new StringBuilder(); + switch(whichEnd) { + case START: + sb.append(lines); + sb.append(s); + break; + case END: + sb.append(s); + sb.append(lines); + break; + case BOTH: + sb.append(lines); + sb.append(s); + sb.append(lines); + break; + } + return sb.toString(); + } + /** * Remove blank lines from the ends of the given string. * @param s The string to remove blank lines from. @@ -3549,25 +3726,31 @@ return s; } StringBuilder sb = new StringBuilder(s); + int index; switch(whichEnd) { case START: - while(sb.length() > 0 && sb.charAt(0) == '\n') { - sb.deleteCharAt(0); + index = sb.indexOf("\n"); + if (index > -1) { + String blank = sb.substring(0, index); + if (isWhitespace(blank)) { + sb.delete(0, index + 1); + } } break; case END: - while(sb.length() > 0 && sb.charAt(sb.length() - 1) == '\n') { - sb.deleteCharAt(sb.length() - 1); + index = sb.lastIndexOf("\n"); + if (index > -1) { + String blank = sb.substring(index, sb.length()); + if (isWhitespace(blank)) { + sb.delete(index, sb.length()); + } } break; case BOTH: default: - while(sb.length() > 0 && sb.charAt(0) == '\n') { - sb.deleteCharAt(0); - } - while(sb.length() > 0 && sb.charAt(sb.length() - 1) == '\n') { - sb.deleteCharAt(sb.length() - 1); - } + s = removeBlankLines(s, START); + s = removeBlankLines(s, END); + sb = new StringBuilder(s); break; } return sb.toString(); @@ -3729,7 +3912,7 @@ StringBuilder sb = new StringBuilder(); List<String> list = reverse(howMany); for (int i = 0; i < list.size(); i++) { - String item = list.get(i).trim(); // TODO: trim? really? + String item = list.get(i); sb.append(item); if (i < list.size() - 1) { if ((howOften == 1 || i % howOften == 1) && !item.endsWith(separator)) { // NOPMD @@ -3876,6 +4059,8 @@ // check if this is an in-line or trailing comment, e.g. // something /star comment star/ more things or // something /star comment star/\n + // In the first case, there is no way to tell if the comment goes with + // the preceding token or the trailing token. int commentTokenIndex = commentToken.getTokenIndex(); boolean tokenOnLeft = true; boolean tokenOnRight = true; @@ -3905,6 +4090,12 @@ else { comment = formatComment(comment); } + String last = stack.peek(); + if (last != null && last.indexOf(comment) == -1) { + last = pop(); + last = new StringBuilder(comment).append(last).toString(); + push(last); + } break; case JavaLexer.DOC_COMMENT: comment = '\n'+ formatDocComment(comment); @@ -4086,51 +4277,49 @@ return ""; } + // TODO: the modifier might have a comment, need to deal with those + // gather the modifiers into a list, then reverse the list so they are // in the right order List<String> modifiers = reverse(howMany); + + // check for comments, if there is one or more single line comments (//...) + // pull them out and save them for later. These comments should be in front + // of the modifier. + // Keep inline comments (e.g. private /* words */ ) attached to the modifier + // and let the sorter deal with them + String lineComment = ""; + for (int i = 0; i < modifiers.size(); i++) { + String mod = modifiers.get(i); + if (mod.indexOf('\n') > -1 && mod.indexOf("//") > -1) { + String[] lines = mod.split("\n"); + for (String line : lines) { + if (line.indexOf("//") > -1) { + lineComment += line + "\n"; + } + else { + modifiers.set(i, lines[lines.length - 1]); + } + } + } + } + if (sortModifiers) { Collections.sort(modifiers, modifierComparator); } - + // modifiers shouldn't be on multiple lines, but comments preceding the // modifier may already be attached and can have multiple lines. // Handle the multiple lines here. StringBuilder sb = new StringBuilder(); + if (!lineComment.isEmpty()) { + sb.append(lineComment); + } for (String modifier : modifiers) { modifier = modifier.trim(); - String[] lines = modifier.split("\n"); - if (lines.length == 1) { - // something like "public " - sb.append(modifier).append(' '); - if (modifier.startsWith("@")) { - sb.append('\n'); - } - } - else { - // multiple lines are likely comment lines - for (int i = 0; i < lines.length; i++) { - String line = lines[i].trim(); - sb.append(line); - // annotations should be on a separate line also, but they - // should have already been handled above - if (i < lines.length - 1 || line.startsWith("@")) { - sb.append('\n'); - } - } - sb.append(' '); - } + sb.append(modifier); + sb.append(modifier.startsWith("@") ? '\n' : ' '); } - - // next indent each line of the modifier - String indented = indent(sb.toString()); - sb = new StringBuilder(indented); - if (sb.length() > 0) { - sb.append(' '); - } - if (sb.length() == 0) { - indent(sb); - } return sb.toString(); } @@ -4145,6 +4334,7 @@ // This list contains all possible modifiers in the correct order. Not all // modifiers are allowed for all constructs, but this method does not check // for illegal modifiers. The parser should flag an error in those cases. + // Annotations count as modifiers, annotations go before public. private String modifiers = "public protected private abstract static final synchronized native sealed non-sealed strictfp transient volatile"; public int compare(String a, String b) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |