forked from phoedos/pmd
Add support for T-SQL using Antlr4 lexer
This commit is contained in:
@ -7088,6 +7088,15 @@
|
||||
"contributions": [
|
||||
"bug"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "pguyot",
|
||||
"name": "Paul Guyot",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/168407?v=4",
|
||||
"profile": "http://paul-guyot.com/",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -229,6 +229,11 @@
|
||||
<artifactId>pmd-swift</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-tsql</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-vm</artifactId>
|
||||
|
@ -28,10 +28,10 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest {
|
||||
static {
|
||||
// note: apex, javascript, visualforce, and scala require java8
|
||||
if (PMDExecutor.isJava7Test()) {
|
||||
SUPPORTED_LANGUAGES_CPD = "Supported languages: [cpp, cs, dart, fortran, gherkin, go, groovy, java, jsp, kotlin, lua, matlab, modelica, objectivec, perl, php, plsql, python, ruby, swift, xml]";
|
||||
SUPPORTED_LANGUAGES_CPD = "Supported languages: [cpp, cs, dart, fortran, gherkin, go, groovy, java, jsp, kotlin, lua, matlab, modelica, objectivec, perl, php, plsql, python, ruby, swift, tsql, xml]";
|
||||
SUPPORTED_LANGUAGES_PMD = "java, jsp, modelica, plsql, pom, vm, wsdl, xml, xsl";
|
||||
} else {
|
||||
SUPPORTED_LANGUAGES_CPD = "Supported languages: [apex, cpp, cs, dart, ecmascript, fortran, gherkin, go, groovy, html, java, jsp, kotlin, lua, matlab, modelica, objectivec, perl, php, plsql, python, ruby, scala, swift, vf, xml]";
|
||||
SUPPORTED_LANGUAGES_CPD = "Supported languages: [apex, cpp, cs, dart, ecmascript, fortran, gherkin, go, groovy, html, java, jsp, kotlin, lua, matlab, modelica, objectivec, perl, php, plsql, python, ruby, scala, swift, tsql, vf, xml]";
|
||||
SUPPORTED_LANGUAGES_PMD = "apex, ecmascript, html, java, jsp, modelica, plsql, pom, scala, vf, vm, wsdl, xml, xsl";
|
||||
}
|
||||
}
|
||||
|
57
pmd-tsql/pom.xml
Normal file
57
pmd-tsql/pom.xml
Normal file
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pmd-tsql</artifactId>
|
||||
<name>PMD TSql</name>
|
||||
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>6.55.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<configuration>
|
||||
<useDefaultDelimiters>false</useDefaultDelimiters>
|
||||
<delimiters>
|
||||
<delimiter>${*}</delimiter>
|
||||
</delimiters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-runtime</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-lang-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
/**
|
||||
* @author pguyot@kallisys.net
|
||||
*/
|
||||
public class TSqlLanguage extends AbstractLanguage {
|
||||
|
||||
public TSqlLanguage() {
|
||||
super("TSql", "tsql", new TSqlTokenizer(), ".sql");
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
|
||||
import net.sourceforge.pmd.lang.antlr.AntlrTokenManager;
|
||||
import net.sourceforge.pmd.lang.tsql.antlr4.TSqlLexer;
|
||||
|
||||
public class TSqlTokenizer extends AntlrTokenizer {
|
||||
|
||||
@Override
|
||||
protected AntlrTokenManager getLexerForSource(SourceCode sourceCode) {
|
||||
CharStream charStream = AntlrTokenizer.getCharStreamFromSourceCode(sourceCode);
|
||||
return new AntlrTokenManager(new TSqlLexer(charStream), sourceCode.getFileName());
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.tsql;
|
||||
|
||||
import net.sourceforge.pmd.lang.BaseLanguageModule;
|
||||
|
||||
/**
|
||||
* Language Module for T-SQL.
|
||||
* @deprecated There is no full PMD support for T-SQL.
|
||||
*/
|
||||
@Deprecated
|
||||
public class TSqlLanguageModule extends BaseLanguageModule {
|
||||
|
||||
/** The name. */
|
||||
public static final String NAME = "T-SQL";
|
||||
/** The terse name. */
|
||||
public static final String TERSE_NAME = "tsql";
|
||||
|
||||
/**
|
||||
* Create a new instance of TSql Language Module.
|
||||
*/
|
||||
public TSqlLanguageModule() {
|
||||
super(NAME, null, TERSE_NAME, "tsql");
|
||||
addVersion("1", null, true);
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.tsql.antlr4;
|
@ -0,0 +1 @@
|
||||
net.sourceforge.pmd.cpd.TSqlLanguage
|
@ -0,0 +1 @@
|
||||
net.sourceforge.pmd.lang.tsql.TSqlLanguageModule
|
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
|
||||
|
||||
public class TSqlTokenizerTest extends CpdTextComparisonTest {
|
||||
|
||||
public TSqlTokenizerTest() {
|
||||
super(".sql");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tokenizer newTokenizer(Properties properties) {
|
||||
return new TSqlTokenizer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResourcePrefix() {
|
||||
return "../lang/tsql/cpd/testdata";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleTest() {
|
||||
doTest("simple");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mailJobTimeLineTest() {
|
||||
doTest("MailJobTimeLine");
|
||||
}
|
||||
}
|
685
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/MailJobTimeLine.sql
vendored
Normal file
685
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/MailJobTimeLine.sql
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2344
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/MailJobTimeLine.txt
vendored
Normal file
2344
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/MailJobTimeLine.txt
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/simple.sql
vendored
Normal file
5
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/simple.sql
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
create procedure p (@v int) as begin
|
||||
declare @f int
|
||||
set @f = @v + 2
|
||||
select @f
|
||||
end
|
28
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/simple.txt
vendored
Normal file
28
pmd-tsql/src/test/resources/net/sourceforge/pmd/lang/tsql/cpd/testdata/simple.txt
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
[Image] or [Truncated image[ Bcol Ecol
|
||||
L1
|
||||
[create] 1 6
|
||||
[procedure] 8 16
|
||||
[p] 18 18
|
||||
[(] 20 20
|
||||
[@v] 21 22
|
||||
[int] 24 26
|
||||
[)] 27 27
|
||||
[as] 29 30
|
||||
[begin] 32 36
|
||||
L2
|
||||
[declare] 2 8
|
||||
[@f] 10 11
|
||||
[int] 13 15
|
||||
L3
|
||||
[set] 2 4
|
||||
[@f] 6 7
|
||||
[=] 9 9
|
||||
[@v] 11 12
|
||||
[+] 14 14
|
||||
[2] 16 16
|
||||
L4
|
||||
[select] 2 7
|
||||
[@f] 9 10
|
||||
L5
|
||||
[end] 1 3
|
||||
EOF
|
3
pom.xml
3
pom.xml
@ -98,7 +98,7 @@
|
||||
<pmd.plugin.version>3.20.0</pmd.plugin.version>
|
||||
<ant.version>1.10.13</ant.version>
|
||||
<javadoc.plugin.version>3.4.1</javadoc.plugin.version>
|
||||
<antlr.version>4.7.2</antlr.version>
|
||||
<antlr.version>4.11.1</antlr.version>
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
@ -1091,6 +1091,7 @@
|
||||
<module>pmd-ruby</module>
|
||||
<module>pmd-swift</module>
|
||||
<module>pmd-test</module>
|
||||
<module>pmd-tsql</module>
|
||||
<module>pmd-vm</module>
|
||||
<module>pmd-xml</module>
|
||||
|
||||
|
Reference in New Issue
Block a user