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

pmd/7.0.x-kotlin/hasImport #2

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
87a4c59
Merge remote-tracking branch 'upstream/pmd/7.0.x' into pmd/7.0.x
stokpop Jan 20, 2022
b12469b
Merge branch 'pmd:pmd/7.0.x' into pmd/7.0.x
stokpop Jan 20, 2022
581ce2a
Adding PMD support for a new ANTLR grammar based language - step 1-4
jborgers Sep 7, 2021
27cf44f
Add official Kotlin ANTLR grammar files, copy and rename some more fr…
jborgers Sep 8, 2021
609c466
Combine KotlinParser, KotlinLexer and UnicodeClasses and use Swift.g4…
jborgers Sep 10, 2021
0f410a2
Handled all steps of "Adding PMD support for a new ANTLR grammar base…
jborgers Sep 13, 2021
2b5c59e
Separate Kotlin.g4 for parser grammar and KotlinLexer.g4 for lexer gr…
jborgers Sep 15, 2021
6bdd6ee
Fix compilation issues
oowekyala Sep 15, 2021
cd9c991
Fix pmd warning
oowekyala Sep 15, 2021
1ae9d17
checkstyle issues
oowekyala Sep 15, 2021
0c25b16
upped antlr plugin version, fix AST errors by using separate UnicodeC…
stokpop Oct 13, 2021
c1de14b
added FunctionNameTooShort test in bestpractices category for Kotlin,…
stokpop Oct 13, 2021
07fa95a
added kotlin xpath function 'pmd-kotlin:hasChildren(3)' as test case …
stokpop Oct 15, 2021
340fa40
added kotlin Simple parser test
stokpop Oct 15, 2021
f040487
fix checkstyle issues
stokpop Oct 15, 2021
186fb84
moved libDirectory setting for kotlin to pmd-kotlin pom.xml
stokpop Oct 15, 2021
9f9307e
upped pmd-designer.version to 7.0.0-SNAPSHOT
stokpop Nov 25, 2021
67a1a9b
add resources to the pmd-kotlin jar so rule definitions files can be …
stokpop Nov 25, 2021
dc1b86d
set version to 7.0.0-kotlin-SNAPSHOT to avoid mixups in 7.0.0-SNAPSHO…
stokpop Jan 20, 2022
a20676d
Merge remote-tracking branch 'origin/pmd/7.0.x' into pmd/7.0.x
stokpop Jan 31, 2022
3bcf2e6
Initial version hasImport - Request for Kotlin XPath function as simp…
jborgers Mar 11, 2024
cbe5772
removed redundant hasImport def
jborgers Mar 15, 2024
d1dac39
fixes various review remarks
jborgers Mar 15, 2024
1f4146e
addresses a few more review remarks
jborgers Mar 15, 2024
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
2 changes: 1 addition & 1 deletion .ci/build.sh
Expand Up @@ -87,7 +87,7 @@ function build() {
pmd_ci_log_group_end

if pmd_ci_maven_isSnapshotBuild; then
if [ "${PMD_CI_MAVEN_PROJECT_VERSION}" != "7.0.0-SNAPSHOT" ]; then
if [ "${PMD_CI_MAVEN_PROJECT_VERSION}" != "7.0.0-kotlin-SNAPSHOT" ]; then
pmd_ci_log_group_start "Executing PMD dogfood test with ${PMD_CI_MAVEN_PROJECT_VERSION}"
./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false
sed -i 's/<version>[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}.*<\/version>\( *<!-- pmd.dogfood.version -->\)/<version>'"${PMD_CI_MAVEN_PROJECT_VERSION}"'<\/version>\1/' pom.xml
Expand Down
38 changes: 37 additions & 1 deletion antlr4-wrapper.xml
Expand Up @@ -31,9 +31,45 @@
<property name="base-visitor-name" value="${lang-name}BaseVisitor"/>
<property name="base-visitor-file" value="${target-package-dir}/${base-visitor-name}.java"/>

<property name="listener-name" value="${lang-name}Listener"/>
<property name="listener-file" value="${target-package-dir}/${visitor-name}.java"/>

<property name="base-listener-name" value="${lang-name}BaseListener"/>
<property name="base-listener-file" value="${target-package-dir}/${base-visitor-name}.java"/>

<property name="node-itf-name" value="${lang-name}Node"/>
<property name="base-class-name" value="Abstract${lang-name}Node"/>

<condition property="rename-parser">
<and>
<not>
<available file="${parser-file}"/>
</not>
<available file="${target-package-dir}/${lang-name}.java"/>
</and>
</condition>

<target name="rename-parser" description="Rename the parser to our conventional name if needed"
if="rename-parser">
<replace file="${target-package-dir}/${lang-name}.java">
<replacefilter token="class ${lang-name} "
value="class ${parser-name} "/>
<replacefilter token="public ${lang-name}(TokenStream input)"
value="public ${parser-name}(TokenStream input)"/>
</replace>
<replace dir="${target-package-dir}">
<include name="${lang-name}.java"/>
<include name="${visitor-name}.java"/>
<include name="${base-visitor-name}.java"/>
<include name="${listener-name}.java"/>
<include name="${base-listener-name}.java"/>
<replacefilter token="${lang-name}." value="${parser-name}."/>
</replace>

<move file="${target-package-dir}/${lang-name}.java"
tofile="${parser-file}"/>
</target>

<target name="cpd-language" description="Adapt Antlr sources for CPD-only languages">
<!-- We only need the Lexer file. -->
<delete file="${parser-file}"/>
Expand All @@ -45,7 +81,7 @@
</delete>
</target>

<target name="pmd-language" description="Adapt Antlr sources for PMD languages">
<target name="pmd-language" description="Adapt Antlr sources for PMD languages" depends="rename-parser">

<!-- Adapt parser. -->
<replace file="${parser-file}">
Expand Down
4 changes: 2 additions & 2 deletions docs/_config.yml
@@ -1,8 +1,8 @@
repository: pmd/pmd

pmd:
version: 7.0.0-SNAPSHOT
previous_version: 6.42.0
version: 7.0.0-kotlin-SNAPSHOT
previous_version: 6.41.0
date: ??-?????-2022
release_type: major

Expand Down
29 changes: 29 additions & 0 deletions docs/_data/xpath_funs.yml
Expand Up @@ -172,3 +172,32 @@ langs:
outcome: "Matches calls to any method with 2 `int` parameters (!= argument)"
- code: '//ConstructorCall[pmd-java:matchesSig("java.util.ArrayList#new(int)")]'
outcome: "Matches constructors calls of ArrayList with a single int parameter"

- name: "Kotlin"
ns: "pmd-kotlin"
funs:
- name: hasChildren
returnType: "xs:boolean"
shortDescription: "Tests if a node has children"
description: "Returns true if the Node has children. This is for test purposes only."
parameters:
- name: "count"
type: "xs:decimal"
description: "The number of children."
examples:
- code: '//Identifier[pmd-kotlin:hasChildren(3)]'
outcome: "true or false"

- name: hasImport
jborgers marked this conversation as resolved.
Show resolved Hide resolved
returnType: "xs:boolean"
shortDescription: "Test for an import header"
description: "Returns true if the document has the specified package in the import header"
parameters:
- name: "package"
type: "xs:string"
description: "The fully qualified package name"
examples:
- code: '/KotlinFile[pmd-kotlin:hasImport('javax.xml.xpath')]'
outcome: "true or false"
- code: '//FunctionBody//T-Identifier[@Text='newXPath' and pmd-kotlin:hasImport('javax.xml.xpath')]'
outcome: "true or false"
2 changes: 1 addition & 1 deletion pmd-apex-jorje/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-apex/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-core/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
Expand Up @@ -88,6 +88,12 @@ protected TerminalNode getToken(int kind, int idx) {
return pmdWrapper != null ? pmdWrapper.asAntlrNode() : null;
}

protected List<TerminalNode> getTokens(int kind) {
return children(BaseAntlrTerminalNode.class)
.filter(it -> it.getTokenKind() == kind)
.toList(BaseAntlrTerminalNode::asAntlrNode);
}

protected void copyFrom(BaseAntlrInnerNode<N> other) {
asAntlrNode().copyFrom(other.asAntlrNode());
}
Expand Down
2 changes: 1 addition & 1 deletion pmd-cpp/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-cs/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-dart/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-dist/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-doc/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-fortran/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-go/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-groovy/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-java/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-javascript/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pmd-jsp/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

Expand Down
20 changes: 18 additions & 2 deletions pmd-kotlin/pom.xml
Expand Up @@ -7,15 +7,29 @@
<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<version>7.0.0-kotlin-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<properties>
<antlr4.visitor>true</antlr4.visitor>
</properties>

<build>
<!-- needed for pmd sonar plugin -->
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<configuration combine.self="override">
<libDirectory>src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast</libDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -29,9 +43,11 @@
</goals>
<configuration>
<target>
<ant antfile="${antlr4.ant.wrapper}" target="cpd-language">
<ant antfile="${antlr4.ant.wrapper}" target="pmd-language">
<property name="lang-name" value="Kotlin" />
<property name="lang-terse-name" value="kotlin" />
<property name="root-node-name" value="File" />
<property name="node-prefix" value="Kt" />
</ant>
</target>
</configuration>
Expand Down