Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #10272: Upgrade Java Grammar from ANTLR2 to ANTLR4 #10280

Merged
merged 8 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions .ci/jsoref-spellchecker/whitelist.words
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ breadcrumbs
bsr
Bsubscribe
BTest
btnfr
buf
bugdatabase
bugfixes
Expand Down Expand Up @@ -277,10 +278,12 @@ dalvik
Daniil
daniilyar
Darguments
darray
Datasource
DATETIME
daveho
davidwalsh
DBFF
Dcheckstyle
dcm
DDDD
Expand All @@ -306,6 +309,7 @@ detailnodetreestringprinter
devops
Dexec
dfa
DFFF
Dfile
dfn
Dfoo
Expand Down Expand Up @@ -717,13 +721,14 @@ kbd
kclee
KDoc
keygen
Kochurkin
konstantinos
Kordas
Kotlin
lambdabodylength
lambdaparametername
lbc
LBRACK
lbrack
lbt
lcurly
Leanback
Expand Down Expand Up @@ -1049,7 +1054,7 @@ qwe
qwerty
rawtypes
rb
RBRACK
rbrack
rcurly
rdiachenko
RDz
Expand Down
2 changes: 1 addition & 1 deletion .ci/no-exception-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ openjdk16-with-checks-nonjavadoc-error)
cd .ci-temp/contribution/checkstyle-tester
cp ../../../.ci/openjdk-projects-to-test-on.config openjdk-projects-to-test-on.config
sed -i '/ <!-- Filters -->/r ../../../.ci/openjdk16-excluded.files' checks-nonjavadoc-error.xml
export MAVEN_OPTS="-Xmx2048m"
export MAVEN_OPTS="-Xmx7168m"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get by with less memory than this, but execution is faster with increased max heap size.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 gigs? Are you sure machines even have that much? Some people could probably not run that locally since they have that much memory.

Copy link
Member Author

@nrmancuso nrmancuso Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increased memory usage is an unfortunate side effect of ANTLR4; it caches DFA states to help speed up parsing. On "normal" sized repos, memory usage is usually increased, but not greatly. However, when we parse 50,000+ files, there is a noticeable increase in memory usage. I have a couple of tricks (clearing DFA cache, two stage parsing), that can improve the memory performance of ANTLR4 on gigantic repos like this, but then performance (speed/ time to parse) suffers across the board for all repos.

That said, we can get by on openjdk14 with 6 GB, but after a few tries, I noticed that parsing is a bit faster with 7 GB.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am more concerned that this can't be run locally as most people may not have 7 gigs available.

For now we can ignore this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this update, not ideal, but we can improve later

groovy ./diff.groovy --listOfProjects openjdk-projects-to-test-on.config \
--mode single --allowExcludes \
--patchConfig checks-nonjavadoc-error.xml \
Expand Down
24 changes: 24 additions & 0 deletions .ci/openjdk16-excluded.files
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,27 @@
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="[\\/]test[\\/]langtools[\\/]tools[\\/]javac[\\/]8245153[\\/]T8245153.java$"/>
</module>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="[\\/]test[\\/]langtools[\\/]tools[\\/]javac[\\/]api[\\/]TestGetElementReferenceDataWithErrors.java$"/>
</module>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="[\\/]test[\\/]langtools[\\/]tools[\\/]javac[\\/]failover[\\/]FailOver15.java$"/>
</module>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="[\\/]test[\\/]langtools[\\/]tools[\\/]javac[\\/]failover[\\/]FailOver01.java$"/>
</module>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="[\\/]test[\\/]langtools[\\/]tools[\\/]javac[\\/]TryWithResources[\\/]PlainTry.java$"/>
</module>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="[\\/]test[\\/]langtools[\\/]tools[\\/]javac[\\/]var_implicit_lambda[\\/]VarInImplicitLambdaNegTest01.java$"/>
</module>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="[\\/]test[\\/]langtools[\\/]tools[\\/]javac[\\/]parser[\\/]8081769[\\/]T8081769.java$"/>
</module>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="[\\/]test[\\/]langtools[\\/]tools[\\/]javac[\\/]LabeledDeclaration.java$"/>
</module>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="[\\/]test[\\/]langtools[\\/]tools[\\/]javac[\\/]generics[\\/]6413682[\\/]T6413682.java$"/>
</module>
3 changes: 2 additions & 1 deletion .ci/pitest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pitest-annotation|pitest-design \
|pitest-main \
|pitest-coding \
|pitest-regexp \
|pitest-meta)
|pitest-meta \
|pitest-java-ast-visitor)
mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=();
checkPitestReport "${ignoredItems[@]}"
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/no-exception-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,23 @@ jobs:
run: mvn -e --no-transfer-progress clean install -Pno-validations

- run: ./.ci/no-exception-test.sh no-exception-only-javadoc

# this execution should stay on github actions due to time/ memory limits in other CI
no-exception-openjdk16:
runs-on: ubuntu-latest
steps:
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8

- name: Install dependencies
run: sudo apt install groovy

- name: Checkout repository
uses: actions/checkout@v2

- name: Install checkstyle
run: mvn -e --no-transfer-progress clean install -Pno-validations

- run: .ci/no-exception-test.sh openjdk16-with-checks-nonjavadoc-error
30 changes: 30 additions & 0 deletions .github/workflows/pitest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: pitest workflow

on:
push:
branches:
- master
pull_request:

jobs:
pitest9:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8

- name: Generate pitest report
run: ./.ci/pitest.sh pitest-java-ast-visitor

- name: Archive report
if: always()
uses: actions/upload-artifact@v2
with:
name: pitest-report-java-ast-visitor
path: /home/runner/work/checkstyle/checkstyle/target/pit-reports/
retention-days: 7
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
2 changes: 0 additions & 2 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ blocks:
# until https://github.com/checkstyle/checkstyle/issues/9248
# - mvn -e clean install -Pno-validations
# && .ci/validation.sh no-violation-test-configurate
- mvn -e --no-transfer-progress clean install -Pno-validations
&& .ci/no-exception-test.sh openjdk16-with-checks-nonjavadoc-error
rnveach marked this conversation as resolved.
Show resolved Hide resolved
commands:
- sem-version java 11
- echo "eval of CMD is starting";
Expand Down
13 changes: 6 additions & 7 deletions config/ant-phase-verify.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<fileset dir="src"
includes="**/*"
excludes="it/resources/**/*,it/resources-noncompilable/**/*,
test/resources/**/*,test/resources-noncompilable/**/*"/>
test/resources/**/*,test/resources-noncompilable/**/*,**/gen/**"/>
<formatter type="plain"/>
<formatter type="xml" toFile="${mvn.project.build.directory}/cs_errors.xml"/>
<classpath path="${mvn.runtime_classpath}"/>
Expand Down Expand Up @@ -116,12 +116,11 @@
<!-- 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/**/Input*.txt"/>

<!-- Exclude all peripheral files generated by ANTLR -->
<exclude name="**/gen/**"/>

</fileset>
</path>
Expand Down
2 changes: 0 additions & 2 deletions config/checkstyle_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,6 @@
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
5 changes: 5 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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is needed to cover the SINGLE_LINE_COMMENT lexer rule's empty alternative.

files="src[\\/]test[\\/]resources[\\/].*[\\/]InputAntlr4AstRegressionCassandraInputWithComments\.java"/>

<!-- Grammar specific input file, should have exact structure to reproduce the case. -->
<suppress checks="NewlineAtEndOfFile"
Expand Down Expand Up @@ -66,6 +68,9 @@
<suppress id="lineLength"
files="src[\\/]test[\\/]resources[\\/].*[\\/]abstractjavadoc[\\/]InputAbstractJavadocLeaveToken.*\.java"/>

<!-- 'fileNamePattern' property requires long paths due to multiple files with the same name -->
<suppress id="lineLength" files=".ci[\\/]openjdk14-excluded\.files"/>

<!-- we can not change expected as it will require change of main class logic -->
<suppress id="lineLength"
files="src[\\/]test[\\/]resources[\\/].*[\\/].*ExpectedXMLLogger.*\.xml"/>
Expand Down
13 changes: 9 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|CheckstyleParserErrorStrategy" 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>

<file name="DefaultLogger">
Expand Down Expand Up @@ -111,6 +111,12 @@
<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>
<file name="TokenTypes">
<allow class="org.antlr.v4.runtime.Recognizer"/>
</file>
</subpackage>

<subpackage name="checks">
Expand Down Expand Up @@ -166,7 +172,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
2 changes: 0 additions & 2 deletions config/intellij-idea-inspections.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4606,8 +4606,6 @@
,com.puppycrawl.tools.checkstyle.AbstractTreeTestSupport,verify.*, ,
,com.google.checkstyle.test.base.AbstractModuleTestSupport,verify.*, ,
,com.puppycrawl.tools.checkstyle.internal.TestUtil,assert.*, ,
,com.puppycrawl.tools.checkstyle.grammar.AstRegressionTest.AssertGeneratedJavaLexer,verify.*, ,
,com.puppycrawl.tools.checkstyle.grammar.AstRegressionTest.AssertGenTextBlockLexer,verify.*, ,
,nl.jqno.equalsverifier.EqualsVerifier,verify.*, ,
,org.checkstyle.base.AbstractItModuleTestSupport,verify.*, ,
,org.powermock.api.mockito.PowerMockito,verify.*"/>
Expand Down
11 changes: 0 additions & 11 deletions config/pmd-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,6 @@
</properties>
</rule>

<rule ref="category/java/codestyle.xml/ShortMethodName">
<properties>
<!-- This inherited from GeneratedJavaLexer. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='AssertGeneratedJavaLexer']
//MethodDeclaration[@Name='LA']
| //ClassOrInterfaceDeclaration[@SimpleName='AssertGenTextBlockLexer']
//MethodDeclaration[@Name='LA']"/>
</properties>
</rule>

<rule ref="category/java/design.xml/UseObjectForClearerAPI">
<properties>
<!-- This is checking for amount of String arguments more than 3 (hardcoded).
Expand Down
16 changes: 13 additions & 3 deletions config/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@
| //ClassOrInterfaceDeclaration[@SimpleName='AbstractImportControl']
//MethodDeclaration[@Name='checkAccess']
| //ClassOrInterfaceDeclaration[@SimpleName='HandlerFactory']
//MethodDeclaration[@Name='getHandler']"/>
//MethodDeclaration[@Name='getHandler']
| //ClassOrInterfaceDeclaration[@SimpleName='JavaAstVisitor']
//MethodDeclaration[@Name='visitWildCardTypeArgument']"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/EmptyMethodInAbstractClassShouldBeAbstract">
Expand Down Expand Up @@ -320,7 +322,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 +334,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 +389,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>