Merge branch 'pr-2753' into pmd/7.0.x
[cpd] Remove some generated source files we don't use #2753
This commit is contained in:
@ -34,7 +34,18 @@
|
||||
<property name="node-itf-name" value="${lang-name}Node"/>
|
||||
<property name="base-class-name" value="Abstract${lang-name}Node"/>
|
||||
|
||||
<target name="adapt-antlr-sources" description="Adapt antlr sources to the PMD codebase">
|
||||
<target name="cpd-language" description="Adapt Antlr sources for CPD-only languages">
|
||||
<!-- We only need the Lexer file. -->
|
||||
<delete file="${parser-file}"/>
|
||||
<delete>
|
||||
<fileset dir="${target-package-dir}">
|
||||
<include name="*"/>
|
||||
<exclude name="*Lexer.java"/>
|
||||
</fileset>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="pmd-language" description="Adapt Antlr sources for PMD languages">
|
||||
|
||||
<!-- Adapt parser. -->
|
||||
<replace file="${parser-file}">
|
||||
|
@ -16,7 +16,7 @@ Happily for you, to add CPD support for a new language is now easier than ever!
|
||||
|
||||
All you need to do is follow this few steps:
|
||||
|
||||
1. Create a new module for your language, you can take [GO as an example](https://github.com/pmd/pmd/tree/master/pmd-go)
|
||||
1. Create a new module for your language, you can take [the Golang module](https://github.com/pmd/pmd/tree/master/pmd-go) as an example
|
||||
2. Create a Tokenizer
|
||||
|
||||
- For Antlr grammars you can take the grammar from [here](https://github.com/antlr/grammars-v4) and extend [AntlrTokenizer](https://github.com/pmd/pmd/blob/master/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/AntlrTokenizer.java) taking Go as an example
|
||||
@ -35,6 +35,8 @@ All you need to do is follow this few steps:
|
||||
- For JavaCC grammars you should subclass [JavaCCTokenizer](https://github.com/pmd/pmd/blob/master/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/JavaCCTokenizer.java) wich has many examples you could follow, you should also take the [Python implementation](https://github.com/pmd/pmd/blob/master/pmd-python/src/main/java/net/sourceforge/pmd/cpd/PythonTokenizer.java) as reference
|
||||
- For any other scenario you can use [AnyTokenizer](https://github.com/pmd/pmd/blob/master/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AnyTokenizer.java)
|
||||
|
||||
If you're using Antlr or JavaCC, update the pom.xml of your submodule to use the appropriate ant wrapper. See `pmd-go/pom.xml` and `pmd-python/pom.xml` for examples.
|
||||
|
||||
3. Create your [Language](https://github.com/pmd/pmd/blob/master/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractLanguage.java) class
|
||||
|
||||
```java
|
||||
@ -132,4 +134,4 @@ public class DartTokenizerTest extends CpdTextComparisonTest {
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@ -17,6 +17,28 @@
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>antlr-cleanup</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<ant antfile="${antlr4.ant.wrapper}" target="cpd-language">
|
||||
<property name="lang-name" value="CSharp" />
|
||||
<property name="lang-terse-name" value="cs" />
|
||||
</ant>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
|
@ -12,7 +12,7 @@ import net.sourceforge.pmd.cpd.internal.AntlrTokenizer;
|
||||
import net.sourceforge.pmd.cpd.token.AntlrTokenFilter;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrToken;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrTokenManager;
|
||||
import net.sourceforge.pmd.lang.cs.antlr4.CSharpLexer;
|
||||
import net.sourceforge.pmd.lang.cs.ast.CSharpLexer;
|
||||
|
||||
/**
|
||||
* The C# tokenizer.
|
||||
|
@ -1,9 +0,0 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* The class {@link net.sourceforge.pmd.lang.cs.antlr4.CSharpLexer} will be moved to package
|
||||
* {@code net.sourceforge.pmd.lang.cs.ast} with PMD 7.
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.cs.antlr4;
|
@ -17,6 +17,27 @@
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>antlr-cleanup</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<ant antfile="${antlr4.ant.wrapper}" target="cpd-language">
|
||||
<property name="lang-name" value="Dart" />
|
||||
<property name="lang-terse-name" value="dart" />
|
||||
</ant>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
|
@ -26,7 +26,7 @@
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
grammar Dart2;
|
||||
grammar Dart;
|
||||
|
||||
compilationUnit: libraryDefinition | partDeclaration;
|
||||
|
@ -10,7 +10,7 @@ import net.sourceforge.pmd.cpd.internal.AntlrTokenizer;
|
||||
import net.sourceforge.pmd.cpd.token.AntlrTokenFilter;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrToken;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrTokenManager;
|
||||
import net.sourceforge.pmd.lang.dart.antlr4.Dart2Lexer;
|
||||
import net.sourceforge.pmd.lang.dart.ast.DartLexer;
|
||||
|
||||
/**
|
||||
* The Dart Tokenizer
|
||||
@ -20,7 +20,7 @@ public class DartTokenizer extends AntlrTokenizer {
|
||||
@Override
|
||||
protected AntlrTokenManager getLexerForSource(SourceCode sourceCode) {
|
||||
CharStream charStream = AntlrTokenizer.getCharStreamFromSourceCode(sourceCode);
|
||||
return new AntlrTokenManager(new Dart2Lexer(charStream), sourceCode.getFileName());
|
||||
return new AntlrTokenManager(new DartLexer(charStream), sourceCode.getFileName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,19 +54,19 @@ public class DartTokenizer extends AntlrTokenizer {
|
||||
|
||||
private void skipLibraryAndImport(final AntlrToken currentToken) {
|
||||
final int type = currentToken.getKind();
|
||||
if (type == Dart2Lexer.LIBRARY || type == Dart2Lexer.IMPORT) {
|
||||
if (type == DartLexer.LIBRARY || type == DartLexer.IMPORT) {
|
||||
discardingLibraryAndImport = true;
|
||||
} else if (discardingLibraryAndImport && (type == Dart2Lexer.SEMICOLON || type == Dart2Lexer.NEWLINE)) {
|
||||
} else if (discardingLibraryAndImport && (type == DartLexer.SEMICOLON || type == DartLexer.NEWLINE)) {
|
||||
discardingLibraryAndImport = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void skipNewLines(final AntlrToken currentToken) {
|
||||
discardingNL = currentToken.getKind() == Dart2Lexer.NEWLINE;
|
||||
discardingNL = currentToken.getKind() == DartLexer.NEWLINE;
|
||||
}
|
||||
|
||||
private void skipSemicolons(final AntlrToken currentToken) {
|
||||
discardingSemicolon = currentToken.getKind() == Dart2Lexer.SEMICOLON;
|
||||
discardingSemicolon = currentToken.getKind() == DartLexer.SEMICOLON;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* The class {@link net.sourceforge.pmd.lang.dart.antlr4.Dart2Lexer} will be renamed to {@code DartLexter} and
|
||||
* be moved to package {@code net.sourceforge.pmd.lang.dart.ast} with PMD 7.
|
||||
*
|
||||
* <p>All other classes will be removed.
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.dart.antlr4;
|
@ -17,6 +17,27 @@
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>antlr-cleanup</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<ant antfile="${antlr4.ant.wrapper}" target="cpd-language">
|
||||
<property name="lang-name" value="Golang" />
|
||||
<property name="lang-terse-name" value="go" />
|
||||
</ant>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<configuration>
|
||||
|
@ -8,7 +8,7 @@ import org.antlr.v4.runtime.CharStream;
|
||||
|
||||
import net.sourceforge.pmd.cpd.internal.AntlrTokenizer;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrTokenManager;
|
||||
import net.sourceforge.pmd.lang.go.antlr4.GolangLexer;
|
||||
import net.sourceforge.pmd.lang.go.ast.GolangLexer;
|
||||
|
||||
public class GoTokenizer extends AntlrTokenizer {
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* The class {@link net.sourceforge.pmd.lang.go.antlr4.GolangLexer} will be moved to
|
||||
* package {@code net.sourceforge.pmd.lang.go.ast} with PMD 7.
|
||||
*
|
||||
* <p>All other classes will be removed.
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.go.antlr4;
|
@ -17,6 +17,27 @@
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>antlr-cleanup</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<ant antfile="${antlr4.ant.wrapper}" target="cpd-language">
|
||||
<property name="lang-name" value="Kotlin" />
|
||||
<property name="lang-terse-name" value="kotlin" />
|
||||
</ant>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
|
@ -10,7 +10,7 @@
|
||||
* https://github.com/JetBrains/kotlin/tree/master/compiler/testData/psi
|
||||
*/
|
||||
|
||||
lexer grammar Kotlin;
|
||||
lexer grammar KotlinLexer;
|
||||
|
||||
/**
|
||||
* Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt
|
@ -10,7 +10,7 @@ import net.sourceforge.pmd.cpd.internal.AntlrTokenizer;
|
||||
import net.sourceforge.pmd.cpd.token.AntlrTokenFilter;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrToken;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrTokenManager;
|
||||
import net.sourceforge.pmd.lang.kotlin.antlr4.Kotlin;
|
||||
import net.sourceforge.pmd.lang.kotlin.ast.KotlinLexer;
|
||||
|
||||
/**
|
||||
* The Kotlin Tokenizer
|
||||
@ -20,7 +20,7 @@ public class KotlinTokenizer extends AntlrTokenizer {
|
||||
@Override
|
||||
protected AntlrTokenManager getLexerForSource(SourceCode sourceCode) {
|
||||
CharStream charStream = AntlrTokenizer.getCharStreamFromSourceCode(sourceCode);
|
||||
return new AntlrTokenManager(new Kotlin(charStream), sourceCode.getFileName());
|
||||
return new AntlrTokenManager(new KotlinLexer(charStream), sourceCode.getFileName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,15 +52,15 @@ public class KotlinTokenizer extends AntlrTokenizer {
|
||||
|
||||
private void skipPackageAndImport(final AntlrToken currentToken) {
|
||||
final int type = currentToken.getKind();
|
||||
if (type == Kotlin.PACKAGE || type == Kotlin.IMPORT) {
|
||||
if (type == KotlinLexer.PACKAGE || type == KotlinLexer.IMPORT) {
|
||||
discardingPackageAndImport = true;
|
||||
} else if (discardingPackageAndImport && (type == Kotlin.SEMICOLON || type == Kotlin.NL)) {
|
||||
} else if (discardingPackageAndImport && (type == KotlinLexer.SEMICOLON || type == KotlinLexer.NL)) {
|
||||
discardingPackageAndImport = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void skipNewLines(final AntlrToken currentToken) {
|
||||
discardingNL = currentToken.getKind() == Kotlin.NL;
|
||||
discardingNL = currentToken.getKind() == KotlinLexer.NL;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +0,0 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* The class {@link net.sourceforge.pmd.lang.kotlin.antlr4.Kotlin} will be renamed to {@code KotlinLexer} and
|
||||
* be moved to package {@code net.sourceforge.pmd.lang.kotlin.ast} with PMD 7.
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.kotlin.antlr4;
|
@ -17,6 +17,27 @@
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>antlr-cleanup</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<ant antfile="${antlr4.ant.wrapper}" target="cpd-language">
|
||||
<property name="lang-name" value="Lua" />
|
||||
<property name="lang-terse-name" value="lua" />
|
||||
</ant>
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
|
@ -9,7 +9,7 @@ import org.antlr.v4.runtime.CharStream;
|
||||
import net.sourceforge.pmd.cpd.internal.AntlrTokenizer;
|
||||
import net.sourceforge.pmd.cpd.token.AntlrTokenFilter;
|
||||
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrTokenManager;
|
||||
import net.sourceforge.pmd.lang.lua.antlr4.LuaLexer;
|
||||
import net.sourceforge.pmd.lang.lua.ast.LuaLexer;
|
||||
|
||||
/**
|
||||
* The Lua Tokenizer
|
||||
|
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* The class {@link net.sourceforge.pmd.lang.lua.antlr4.LuaLexer} will be moved to
|
||||
* package {@code net.sourceforge.pmd.lang.lua.ast} with PMD 7.
|
||||
*
|
||||
* <p>All other classes will be removed.
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.lua.antlr4;
|
@ -35,7 +35,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<ant antfile="${antlr4.ant.wrapper}">
|
||||
<ant antfile="${antlr4.ant.wrapper}" target="pmd-language">
|
||||
<property name="lang-name" value="Swift" />
|
||||
<property name="lang-terse-name" value="swift" />
|
||||
<property name="root-node-name" value="TopLevel" />
|
||||
|
Reference in New Issue
Block a user