Introduces java 8 integration test module
* Only for testing pmd-java * Activated only if the jdk is 1.8
This commit is contained in:
171
pmd-java8/pom.xml
Normal file
171
pmd-java8/pom.xml
Normal file
@ -0,0 +1,171 @@
|
||||
<?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-java8</artifactId>
|
||||
<name>PMD Java 8 Integration</name>
|
||||
|
||||
<parent>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>5.3.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<config.basedir>${basedir}/../pmd-core</config.basedir>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>${basedir}/src/test/resources</directory>
|
||||
</testResource>
|
||||
<testResource>
|
||||
<directory>${basedir}/src/test/java</directory>
|
||||
<includes>
|
||||
<include>**/testdata/*.java</include>
|
||||
</includes>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<configuration>
|
||||
<useDefaultDelimiters>false</useDefaultDelimiters>
|
||||
<delimiters>
|
||||
<delimiter>${*}</delimiter>
|
||||
</delimiters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!--<plugin>-->
|
||||
<!--<groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!--<artifactId>maven-antrun-plugin</artifactId>-->
|
||||
<!--<inherited>true</inherited>-->
|
||||
<!--<executions>-->
|
||||
<!--<execution>-->
|
||||
<!--<id>generate-sources</id>-->
|
||||
<!--<phase>generate-sources</phase>-->
|
||||
<!--<configuration>-->
|
||||
<!--<target>-->
|
||||
<!--<ant antfile="src/main/ant/alljavacc.xml">-->
|
||||
<!--<property name="target" value="${project.build.directory}/generated-sources/javacc" />-->
|
||||
<!--<property name="javacc.jar" value="${settings.localRepository}/net/java/dev/javacc/javacc/${javacc.version}/javacc-${javacc.version}.jar" />-->
|
||||
<!--</ant>-->
|
||||
<!--</target>-->
|
||||
<!--</configuration>-->
|
||||
<!--<goals>-->
|
||||
<!--<goal>run</goal>-->
|
||||
<!--</goals>-->
|
||||
<!--</execution>-->
|
||||
<!--<execution>-->
|
||||
<!--<id>pmd-clean</id>-->
|
||||
<!--<phase>clean</phase>-->
|
||||
<!--<configuration>-->
|
||||
<!--<target>-->
|
||||
<!--<echo>PMD specific tasks: cleaning generated xdocs</echo>-->
|
||||
<!--<delete quiet="true">-->
|
||||
<!--<fileset dir="${basedir}/src/site/xdoc/rules/" includes="**/*.xml" />-->
|
||||
<!--<fileset dir="${basedir}/src/site/xdoc/" includes="mergedruleset.xml" />-->
|
||||
<!--<fileset dir="${basedir}/src/site/" includes="site.xml" />-->
|
||||
<!--</delete>-->
|
||||
<!--</target>-->
|
||||
<!--</configuration>-->
|
||||
<!--<goals>-->
|
||||
<!--<goal>run</goal>-->
|
||||
<!--</goals>-->
|
||||
<!--</execution>-->
|
||||
<!--</executions>-->
|
||||
<!--</plugin>-->
|
||||
|
||||
<!--<plugin>-->
|
||||
<!--<groupId>org.codehaus.mojo</groupId>-->
|
||||
<!--<artifactId>build-helper-maven-plugin</artifactId>-->
|
||||
<!--<executions>-->
|
||||
<!--<execution>-->
|
||||
<!--<id>add-javacc-generated-sources</id>-->
|
||||
<!--<goals>-->
|
||||
<!--<goal>add-source</goal>-->
|
||||
<!--</goals>-->
|
||||
<!--<configuration>-->
|
||||
<!--<sources>-->
|
||||
<!--<source>${project.build.directory}/generated-sources/javacc</source>-->
|
||||
<!--</sources>-->
|
||||
<!--</configuration>-->
|
||||
<!--</execution>-->
|
||||
<!--</executions>-->
|
||||
<!--</plugin>-->
|
||||
|
||||
<plugin>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-build</artifactId>
|
||||
<configuration>
|
||||
<rulesetsDirectory>${basedir}/src/main/resources/rulesets</rulesetsDirectory>
|
||||
<siteXml>${basedir}/src/site/site.pre.xml</siteXml>
|
||||
<siteXmlTarget>${basedir}/src/site/site.xml</siteXmlTarget>
|
||||
<target>${basedir}/src/site/xdoc/rules</target>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>pre-site</phase>
|
||||
<goals>
|
||||
<goal>pmd-pre-site</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-java</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jaxen</groupId>
|
||||
<artifactId>jaxen</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.javacc</groupId>
|
||||
<artifactId>javacc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.saxon</groupId>
|
||||
<artifactId>saxon</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.saxon</groupId>
|
||||
<artifactId>saxon</artifactId>
|
||||
<classifier>dom</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,39 @@
|
||||
package net.sourceforge.pmd.lang.java.bugs;
|
||||
|
||||
//import java.util.stream.IntStream;
|
||||
//import static java.util.stream.Collectors.toList;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.UsesJavaStreams;
|
||||
|
||||
@Ignore
|
||||
public class InterfaceMethodTest {
|
||||
|
||||
@Test
|
||||
public void should_not_fail() {
|
||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(UsesJavaStreams.class);
|
||||
}
|
||||
|
||||
// Note: If you're using Eclipse or some other IDE to run this test, you _must_ have the regress folder in
|
||||
// the classpath. Normally the IDE doesn't put source directories themselves directly in the classpath, only
|
||||
// the output directories are in the classpath.
|
||||
private ASTCompilationUnit parseAndTypeResolveForClass(Class<?> clazz) {
|
||||
String sourceFile = clazz.getName().replace('.', '/') + ".java";
|
||||
InputStream is = InterfaceMethodTest.class.getClassLoader().getResourceAsStream(sourceFile);
|
||||
if (is == null) {
|
||||
throw new IllegalArgumentException("Unable to find source file " + sourceFile + " for " + clazz);
|
||||
}
|
||||
LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.8").getLanguageVersionHandler();
|
||||
ASTCompilationUnit acu = (ASTCompilationUnit)languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new InputStreamReader(is));
|
||||
languageVersionHandler.getSymbolFacade().start(acu);
|
||||
languageVersionHandler.getTypeResolutionFacade(InterfaceMethodTest.class.getClassLoader()).start(acu);
|
||||
return acu;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package net.sourceforge.pmd.lang.java.bugs;
|
||||
|
||||
import java.io.StringReader;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.symboltable.SymbolFacade;
|
||||
|
||||
@Ignore
|
||||
public class Java8MultipleLambdasTest {
|
||||
|
||||
private static final String MULTIPLE_JAVA_8_LAMBDAS =
|
||||
"public class MultipleLambdas {" + PMD.EOL +
|
||||
" Observer a = (o, arg) -> System.out.println(\"a_\" + arg);" + PMD.EOL +
|
||||
" Observer b = (o, arg) -> System.out.println(\"b_\" + arg);" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
@Test
|
||||
public void should_not_fail() {
|
||||
parseCode(MULTIPLE_JAVA_8_LAMBDAS);
|
||||
}
|
||||
|
||||
private void parseCode(String code) {
|
||||
LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getDefaultVersion().getLanguageVersionHandler();
|
||||
ASTCompilationUnit acu = (ASTCompilationUnit) languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new StringReader(code));
|
||||
SymbolFacade stb = new SymbolFacade();
|
||||
stb.initializeWith(acu);
|
||||
}
|
||||
|
||||
|
||||
// Was failing with :
|
||||
// java.lang.RuntimeException: Variable: image = 'i', line = 3 is already in the symbol table
|
||||
// at net.AbstractJavaScope.checkForDuplicatedNameDeclaration(AbstractJavaScope.java:27)
|
||||
// at net.sourceforge.pmd.lang.java.symboltable.AbstractJavaScope.addDeclaration(AbstractJavaScope.java:21)
|
||||
// at net.sourceforge.pmd.lang.java.symboltable.ScopeAndDeclarationFinder.visit(ScopeAndDeclarationFinder.java:294)
|
||||
// at net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId.jjtAccept(ASTVariableDeclaratorId.java:30)
|
||||
// at net.AbstractJavaNode.childrenAccept(AbstractJavaNode.java:55)
|
||||
// at net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter.visit(JavaParserVisitorAdapter.java:9)
|
||||
// at net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter.visit(JavaParserVisitorAdapter.java:455)
|
||||
// at net.sourceforge.pmd.lang.java.ast.ASTLambdaExpression.jjtAccept(ASTLambdaExpression.java:21)
|
||||
// at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.childrenAccept(AbstractJavaNode.java:55)
|
||||
// at net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter.visit(JavaParserVisitorAdapter.java:9)
|
||||
// at net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter.visit(JavaParserVisitorAdapter.java:312)
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.typeresolution;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import org.junit.Test;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.UsesJavaStreams;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.UsesRepeatableAnnotations;
|
||||
|
||||
|
||||
public class ClassTypeResolverJava8Test {
|
||||
|
||||
@Test
|
||||
public void interface_method_should_be_parseable() {
|
||||
ASTCompilationUnit acu = parseAndTypeResolveForClass18(UsesJavaStreams.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeatable_annotations_method_should_be_parseable() {
|
||||
ASTCompilationUnit acu = parseAndTypeResolveForClass18(UsesRepeatableAnnotations.class);
|
||||
}
|
||||
|
||||
|
||||
public static junit.framework.Test suite() {
|
||||
return new junit.framework.JUnit4TestAdapter(ClassTypeResolverJava8Test.class);
|
||||
}
|
||||
|
||||
private ASTCompilationUnit parseAndTypeResolveForClass18(Class<?> clazz) {
|
||||
return parseAndTypeResolveForClass(clazz, "1.8");
|
||||
}
|
||||
|
||||
// Note: If you're using Eclipse or some other IDE to run this test, you _must_ have the regress folder in
|
||||
// the classpath. Normally the IDE doesn't put source directories themselves directly in the classpath, only
|
||||
// the output directories are in the classpath.
|
||||
private ASTCompilationUnit parseAndTypeResolveForClass(Class<?> clazz, String version) {
|
||||
String sourceFile = clazz.getName().replace('.', '/') + ".java";
|
||||
InputStream is = ClassTypeResolverJava8Test.class.getClassLoader().getResourceAsStream(sourceFile);
|
||||
if (is == null) {
|
||||
throw new IllegalArgumentException("Unable to find source file " + sourceFile + " for " + clazz);
|
||||
}
|
||||
LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion(version).getLanguageVersionHandler();
|
||||
ASTCompilationUnit acu = (ASTCompilationUnit) languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new InputStreamReader(is));
|
||||
languageVersionHandler.getSymbolFacade().start(acu);
|
||||
languageVersionHandler.getTypeResolutionFacade(ClassTypeResolverJava8Test.class.getClassLoader()).start(acu);
|
||||
return acu;
|
||||
}
|
||||
}
|
15
pmd-java8/src/test/java/net/sourceforge/pmd/typeresolution/testdata/UsesJavaStreams.java
vendored
Normal file
15
pmd-java8/src/test/java/net/sourceforge/pmd/typeresolution/testdata/UsesJavaStreams.java
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
public class UsesJavaStreams {
|
||||
interface WithStaticAndDefaultMethod {
|
||||
static void performOn() { }
|
||||
default void myToString() {}
|
||||
}
|
||||
|
||||
class ImplWithStaticAndDefaultMethod implements WithStaticAndDefaultMethod {}
|
||||
|
||||
public void performStuff() {
|
||||
WithStaticAndDefaultMethod.performOn();
|
||||
new ImplWithStaticAndDefaultMethod().myToString();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
import java.lang.annotation.Repeatable;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.UsesRepeatableAnnotations.Multitude;
|
||||
|
||||
@Multitude("1")
|
||||
@Multitude("2")
|
||||
@Multitude("3")
|
||||
@Multitude("4")
|
||||
public class UsesRepeatableAnnotations {
|
||||
|
||||
@Repeatable(Multitudes.class)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Multitude { String value(); }
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Multitudes { Multitude[] value(); }
|
||||
|
||||
}
|
Reference in New Issue
Block a user