Skip to content

Commit

Permalink
Issue #10272: Upgrade Java Grammar from ANTLR2 to ANTLR4
Browse files Browse the repository at this point in the history
  • Loading branch information
nrmancuso committed Jul 7, 2021
1 parent 10a12a0 commit d1be9bd
Show file tree
Hide file tree
Showing 117 changed files with 29,577 additions and 3,462 deletions.
9 changes: 7 additions & 2 deletions .ci/jsoref-spellchecker/whitelist.words
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ breadcrumbs
bsr
Bsubscribe
BTest
btnfr
buf
bugdatabase
bugfixes
Expand Down Expand Up @@ -276,10 +277,12 @@ dalvik
Daniil
daniilyar
Darguments
darray
Datasource
DATETIME
daveho
davidwalsh
DBFF
Dcheckstyle
dcm
DDDD
Expand All @@ -305,6 +308,7 @@ detailnodetreestringprinter
devops
Dexec
dfa
DFFF
Dfile
dfn
Dfoo
Expand Down Expand Up @@ -713,13 +717,14 @@ kbd
kclee
KDoc
keygen
Kochurkin
konstantinos
Kordas
Kotlin
lambdabodylength
lambdaparametername
lbc
LBRACK
lbrack
lbt
lcurly
Leanback
Expand Down Expand Up @@ -1043,7 +1048,7 @@ qwe
qwerty
rawtypes
rb
RBRACK
rbrack
rcurly
rdiachenko
RDz
Expand Down
114 changes: 114 additions & 0 deletions .ci/pitest.sh

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ replay_pid*
.ci/jsoref-spellchecker/spelling-unknown-word-splitter.pl
.ci/jsoref-spellchecker/unknown.words
.ci/jsoref-spellchecker/english.words

# antlr4 grammar generates these
**/gen
**/JavaLexer.tokens
8 changes: 2 additions & 6 deletions config/ant-phase-verify.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,8 @@
<!-- Do not validate possible source code remnants after regression testing -->
<exclude name=".ci-temp/**/*"/>

<!-- Exclude because printed AST has line length > 100 characters -->
<exclude name="**/InputJava14InstanceofWithPatternMatchingAST.txt"/>
<exclude name="**/InputJava14Records.txt"/>
<exclude name="**/InputJava14TextBlocks.txt"/>
<exclude name="**/InputJava14SwitchExpression.txt"/>
<exclude name="**/InputPatternVariableWithModifiers.txt"/>
<!-- Exclude because printed AST is verified by matching checkstyle output -->
<exclude name="**/grammar/**/*.txt"/>

</fileset>
</path>
Expand Down
3 changes: 0 additions & 3 deletions config/checkstyle_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,6 @@
<property name="classes"
value="org.xml.sax.SAXException, org.xml.sax.SAXParseException,
org.apache.commons.beanutils.ConversionException,
org.antlr.v4.runtime.misc.ParseCancellationException,
antlr.RecognitionException, antlr.TokenStreamException,
antlr.TokenStreamRecognitionException, antlr.ANTLRException,
java.lang.StringBuffer"/>
</module>
<module name="IllegalThrows"/>
Expand Down
2 changes: 2 additions & 0 deletions config/checkstyle_non_main_files_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
files="[\\/]test[\\/].*[\\/]asttreestringprinter[\\/]InputAstTreeStringPrinterFullOfSinglelineComments\.java"/>
<suppress checks="NewlineAtEndOfFile"
files="src[\\/]test[\\/]resources[\\/].*[\\/]InputNoCodeInFile6\.java"/>
<suppress checks="NewlineAtEndOfFile"
files="src[\\/]test[\\/]resources[\\/].*[\\/]InputAntlr4AstRegressionCassandraInputWithComments\.java"/>

<!-- Grammar specific input file, should have exact structure to reproduce the case. -->
<suppress checks="NewlineAtEndOfFile"
Expand Down
10 changes: 6 additions & 4 deletions config/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<allow class="com.puppycrawl.tools.checkstyle.XpathFileGeneratorAuditListener"
local-only="true"/>

<file name="DetailAstImpl|JavaParser" regex="true">
<allow pkg="antlr"/>
<file name="DetailAstImpl|JavaParser|JavaAstVisitor" regex="true">
<allow pkg="org.antlr.v4.runtime"/>
</file>
<file name="JavadocDetailNodeParser">
<allow pkg="org.antlr.v4.runtime"/>
Expand All @@ -56,8 +56,8 @@
<allow class="java.math.BigInteger"/>
</file>
<file name="ParserUtil">
<allow class="antlr.Token"/>
<allow class="com.puppycrawl.tools.checkstyle.DetailAstImpl"/>
<allow class="org.antlr.v4.runtime.CommonToken"/>
</file>

<subpackage name="utils">
Expand Down Expand Up @@ -107,6 +107,9 @@
<allow class="com.puppycrawl.tools.checkstyle.Checker" local-only="true"/>
<!-- allowed till https://github.com/checkstyle/checkstyle/issues/3817 -->
<allow pkg="com.puppycrawl.tools.checkstyle.utils"/>
<file name="DetailAST">
<allow class="org.antlr.v4.runtime.Token"/>
</file>
</subpackage>

<subpackage name="checks">
Expand Down Expand Up @@ -162,7 +165,6 @@

<subpackage name="gui" strategyOnMismatch="disallowed">
<!-- until https://github.com/checkstyle/checkstyle/issues/3095 -->
<allow pkg="antlr"/>
<allow class="com.puppycrawl.tools.checkstyle.DetailAstImpl"/>
<allow class="com.puppycrawl.tools.checkstyle.xpath.XpathQueryGenerator" />

Expand Down
12 changes: 10 additions & 2 deletions config/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@
JavadocMethodCheck is in the process of being rewritten. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='PackageObjectFactory']
| //ClassOrInterfaceDeclaration[@SimpleName='JavadocMethodCheck']"/>
| //ClassOrInterfaceDeclaration[@SimpleName='JavadocMethodCheck']
| //ClassOrInterfaceDeclaration[@SimpleName='JavaAstVisitor']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/ExcessiveClassLength">
Expand All @@ -331,7 +332,7 @@
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='JavadocTokenTypes'
or @SimpleName='TokenTypes' or @SimpleName='RequireThisCheck'
or @SimpleName='JavadocMethodCheck']"/>
or @SimpleName='JavadocMethodCheck' or @SimpleName='JavaAstVisitor']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/ExcessiveParameterList">
Expand Down Expand Up @@ -386,4 +387,11 @@
<!-- Not configurable, decreases readability. -->
<exclude name="UseStringBufferForStringAppends"/>
</rule>

<rule ref="category/java/design.xml/ExcessivePublicCount">
<properties>
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='JavaAstVisitor']"/>
</properties>
</rule>
</ruleset>
11 changes: 11 additions & 0 deletions config/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,15 @@
<suppress id="ImportControlTest"
files="[\\/]src[\\/]test[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]xpath[\\/]XpathQueryGeneratorTest.java"/>

<!-- required by JavaAstVisitor design -->
<suppress checks="MethodCount"
files="[\\/]src[\\/]main[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]JavaAstVisitor.java"/>
<suppress checks="FileLength"
files="[\\/]src[\\/]main[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]JavaAstVisitor.java"/>
<suppress checks="ClassFanOutComplexity"
files="[\\/]src[\\/]main[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]JavaAstVisitor.java"/>

<!-- DetailAST API requires large number of methods -->
<suppress checks="MethodCount"
files="[\\/]src[\\/]main[\\/]java[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]DetailAstImpl.java"/>
</suppressions>
109 changes: 53 additions & 56 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,6 @@
<artifactId>picocli</artifactId>
<version>4.6.1</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
Expand Down Expand Up @@ -537,19 +532,6 @@
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>antlr-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.antlr</groupId>
Expand All @@ -565,19 +547,6 @@
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>java</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -652,7 +621,7 @@
</sourceDirectories>
<excludes>
**/it/resources/**/*,**/it/resources-noncompilable/**/*,
,**/test/resources/**/*,**/test/resources-noncompilable/**/*
,**/test/resources/**/*,**/test/resources-noncompilable/**/*,**/gen/**/*
</excludes>
</configuration>
<goals>
Expand Down Expand Up @@ -861,11 +830,13 @@
<excludes>
<!-- Parser related classes -->
<exclude>
com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer
com.puppycrawl.tools.checkstyle.grammar.java.JavaParser*
</exclude>
<exclude>com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaLexer</exclude>
<exclude>
com.puppycrawl.tools.checkstyle.grammar.GeneratedTextBlockLexer
com.puppycrawl.tools.checkstyle.grammar.java.JavaLexer
</exclude>
<exclude>
com.puppycrawl.tools.checkstyle.JavaParser.JavaParserErrorStrategy
</exclude>
<exclude>
com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocParser*
Expand Down Expand Up @@ -1213,38 +1184,19 @@
-->
</plugin>

<!-- Generate the ANTLRv2 grammar -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>antlr-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<sourceDirectory>
${basedir}/src/main/resources/com/puppycrawl/tools/checkstyle/grammar
</sourceDirectory>
<grammars>java*.g</grammars>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- Generate the ANTLRv4 grammar -->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${antlr4.version}</version>
<configuration>
<visitor>false</visitor>
<visitor>true</visitor>
<listener>false</listener>
<sourceDirectory>${basedir}/src/main/resources/</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/antlr/</outputDirectory>
<includes>
<include>com/puppycrawl/tools/checkstyle/grammar/javadoc/*.g4</include>
<include>com/puppycrawl/tools/checkstyle/grammar/java/*.g4</include>
</includes>
</configuration>
<executions>
Expand Down Expand Up @@ -3388,5 +3340,50 @@
</plugins>
</build>
</profile>
<profile>
<id>pitest-JavaAstVisitor</id>
<properties>
<skipTests>true</skipTests>
<jacoco.skip>true</jacoco.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>${pitest.plugin.version}</version>
<configuration>
<mutators>
<mutator>CONDITIONALS_BOUNDARY</mutator>
<mutator>CONSTRUCTOR_CALLS</mutator>
<mutator>FALSE_RETURNS</mutator>
<mutator>INCREMENTS</mutator>
<mutator>INVERT_NEGS</mutator>
<mutator>MATH</mutator>
<mutator>NEGATE_CONDITIONALS</mutator>
<mutator>REMOVE_CONDITIONALS</mutator>
<mutator>RETURN_VALS</mutator>
<mutator>TRUE_RETURNS</mutator>
<mutator>VOID_METHOD_CALLS</mutator>
</mutators>
<targetClasses>
<param>com.puppycrawl.tools.checkstyle.JavaAstVisitor</param>
</targetClasses>
<targetTests>
<param>com.puppycrawl.tools.checkstyle.grammar.*</param>
</targetTests>
<excludedTestClasses>
<param>*.Input*</param>
</excludedTestClasses>
<coverageThreshold>92</coverageThreshold>
<mutationThreshold>87</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

0 comments on commit d1be9bd

Please sign in to comment.