Same for kotlin

This commit is contained in:
Clément Fournier
2020-08-30 18:59:48 +02:00
parent 1474ed6e79
commit 9ef8c151e2
3 changed files with 27 additions and 6 deletions

View File

@@ -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>

View File

@@ -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

View File

@@ -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