forked from phoedos/pmd
Introduces java 8 integration test module
* Only for testing pmd-java * Activated only if the jdk is 1.8
This commit is contained in:
@ -57,7 +57,7 @@ public class ClassTypeResolverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void acceptanceTest() {
|
public void acceptanceTest() {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(ArrayListFound.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(ArrayListFound.class);
|
||||||
assertEquals(ArrayListFound.class, acu.getFirstDescendantOfType(ASTTypeDeclaration.class).getType());
|
assertEquals(ArrayListFound.class, acu.getFirstDescendantOfType(ASTTypeDeclaration.class).getType());
|
||||||
assertEquals(ArrayListFound.class, acu.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getType());
|
assertEquals(ArrayListFound.class, acu.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getType());
|
||||||
ASTImportDeclaration id = acu.getFirstDescendantOfType(ASTImportDeclaration.class);
|
ASTImportDeclaration id = acu.getFirstDescendantOfType(ASTImportDeclaration.class);
|
||||||
@ -70,7 +70,7 @@ public class ClassTypeResolverTest {
|
|||||||
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTVariableDeclarator.class).getType());
|
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTVariableDeclarator.class).getType());
|
||||||
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTFieldDeclaration.class).getType());
|
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTFieldDeclaration.class).getType());
|
||||||
|
|
||||||
acu = parseAndTypeResolveForClass(DefaultJavaLangImport.class);
|
acu = parseAndTypeResolveForClass15(DefaultJavaLangImport.class);
|
||||||
assertEquals(String.class, acu.getFirstDescendantOfType(ASTClassOrInterfaceType.class).getType());
|
assertEquals(String.class, acu.getFirstDescendantOfType(ASTClassOrInterfaceType.class).getType());
|
||||||
assertEquals(Override.class, acu.findDescendantsOfType(ASTName.class).get(1).getType());
|
assertEquals(Override.class, acu.findDescendantsOfType(ASTName.class).get(1).getType());
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ public class ClassTypeResolverTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEnumAnonymousInnerClass() {
|
public void testEnumAnonymousInnerClass() {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(EnumWithAnonymousInnerClass.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(EnumWithAnonymousInnerClass.class);
|
||||||
Class<?> inner = acu.getFirstDescendantOfType(ASTAllocationExpression.class)
|
Class<?> inner = acu.getFirstDescendantOfType(ASTAllocationExpression.class)
|
||||||
.getFirstDescendantOfType(ASTClassOrInterfaceType.class).getType();
|
.getFirstDescendantOfType(ASTClassOrInterfaceType.class).getType();
|
||||||
assertEquals("net.sourceforge.pmd.typeresolution.testdata.EnumWithAnonymousInnerClass$1",
|
assertEquals("net.sourceforge.pmd.typeresolution.testdata.EnumWithAnonymousInnerClass$1",
|
||||||
@ -89,7 +89,7 @@ public class ClassTypeResolverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtraTopLevelClass() throws ClassNotFoundException {
|
public void testExtraTopLevelClass() throws ClassNotFoundException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(ExtraTopLevelClass.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(ExtraTopLevelClass.class);
|
||||||
Class<?> theExtraTopLevelClass = Class.forName("net.sourceforge.pmd.typeresolution.testdata.TheExtraTopLevelClass");
|
Class<?> theExtraTopLevelClass = Class.forName("net.sourceforge.pmd.typeresolution.testdata.TheExtraTopLevelClass");
|
||||||
// First class
|
// First class
|
||||||
ASTTypeDeclaration typeDeclaration = (ASTTypeDeclaration) acu.jjtGetChild(1);
|
ASTTypeDeclaration typeDeclaration = (ASTTypeDeclaration) acu.jjtGetChild(1);
|
||||||
@ -105,7 +105,7 @@ public class ClassTypeResolverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInnerClass() throws ClassNotFoundException {
|
public void testInnerClass() throws ClassNotFoundException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(InnerClass.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(InnerClass.class);
|
||||||
Class<?> theInnerClass = Class.forName("net.sourceforge.pmd.typeresolution.testdata.InnerClass$TheInnerClass");
|
Class<?> theInnerClass = Class.forName("net.sourceforge.pmd.typeresolution.testdata.InnerClass$TheInnerClass");
|
||||||
// Outer class
|
// Outer class
|
||||||
ASTTypeDeclaration typeDeclaration = acu.getFirstDescendantOfType(ASTTypeDeclaration.class);
|
ASTTypeDeclaration typeDeclaration = acu.getFirstDescendantOfType(ASTTypeDeclaration.class);
|
||||||
@ -122,7 +122,7 @@ public class ClassTypeResolverTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnonymousInnerClass() throws ClassNotFoundException {
|
public void testAnonymousInnerClass() throws ClassNotFoundException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(AnonymousInnerClass.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(AnonymousInnerClass.class);
|
||||||
Class<?> theAnonymousInnerClass = Class.forName("net.sourceforge.pmd.typeresolution.testdata.AnonymousInnerClass$1");
|
Class<?> theAnonymousInnerClass = Class.forName("net.sourceforge.pmd.typeresolution.testdata.AnonymousInnerClass$1");
|
||||||
// Outer class
|
// Outer class
|
||||||
ASTTypeDeclaration typeDeclaration = acu.getFirstDescendantOfType(ASTTypeDeclaration.class);
|
ASTTypeDeclaration typeDeclaration = acu.getFirstDescendantOfType(ASTTypeDeclaration.class);
|
||||||
@ -137,7 +137,7 @@ public class ClassTypeResolverTest {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testLiterals() throws JaxenException {
|
public void testLiterals() throws JaxenException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(Literals.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Literals.class);
|
||||||
List<ASTLiteral> literals = acu.findChildNodesWithXPath("//Literal");
|
List<ASTLiteral> literals = acu.findChildNodesWithXPath("//Literal");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ public class ClassTypeResolverTest {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnaryNumericPromotion() throws JaxenException {
|
public void testUnaryNumericPromotion() throws JaxenException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(Promotion.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Promotion.class);
|
||||||
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryNumericPromotion']]//Expression[UnaryExpression]");
|
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryNumericPromotion']]//Expression[UnaryExpression]");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@ -307,7 +307,7 @@ public class ClassTypeResolverTest {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testBinaryNumericPromotion() throws JaxenException {
|
public void testBinaryNumericPromotion() throws JaxenException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(Promotion.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Promotion.class);
|
||||||
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryNumericPromotion']]//Expression[AdditiveExpression]");
|
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryNumericPromotion']]//Expression[AdditiveExpression]");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ public class ClassTypeResolverTest {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testBinaryStringPromotion() throws JaxenException {
|
public void testBinaryStringPromotion() throws JaxenException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(Promotion.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Promotion.class);
|
||||||
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryStringPromotion']]//Expression");
|
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryStringPromotion']]//Expression");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@ -392,7 +392,7 @@ public class ClassTypeResolverTest {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnaryLogicalOperators() throws JaxenException {
|
public void testUnaryLogicalOperators() throws JaxenException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(Operators.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class);
|
||||||
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryLogicalOperators']]//Expression");
|
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryLogicalOperators']]//Expression");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@ -406,7 +406,7 @@ public class ClassTypeResolverTest {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testBinaryLogicalOperators() throws JaxenException {
|
public void testBinaryLogicalOperators() throws JaxenException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(Operators.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class);
|
||||||
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryLogicalOperators']]//Expression");
|
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryLogicalOperators']]//Expression");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@ -431,7 +431,7 @@ public class ClassTypeResolverTest {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnaryNumericOperators() throws JaxenException {
|
public void testUnaryNumericOperators() throws JaxenException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(Operators.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class);
|
||||||
List<TypeNode> expressions = new ArrayList<TypeNode>();
|
List<TypeNode> expressions = new ArrayList<TypeNode>();
|
||||||
expressions.addAll(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryNumericOperators']]//Expression"));
|
expressions.addAll(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryNumericOperators']]//Expression"));
|
||||||
expressions.addAll(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryNumericOperators']]//PostfixExpression"));
|
expressions.addAll(acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryNumericOperators']]//PostfixExpression"));
|
||||||
@ -453,7 +453,7 @@ public class ClassTypeResolverTest {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testBinaryNumericOperators() throws JaxenException {
|
public void testBinaryNumericOperators() throws JaxenException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(Operators.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class);
|
||||||
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryNumericOperators']]//Expression");
|
List<ASTExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryNumericOperators']]//Expression");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@ -473,7 +473,7 @@ public class ClassTypeResolverTest {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testAssignmentOperators() throws JaxenException {
|
public void testAssignmentOperators() throws JaxenException {
|
||||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(Operators.class);
|
ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class);
|
||||||
List<ASTStatementExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'assignmentOperators']]//StatementExpression");
|
List<ASTStatementExpression> expressions = acu.findChildNodesWithXPath("//Block[preceding-sibling::MethodDeclarator[@Image = 'assignmentOperators']]//StatementExpression");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@ -498,16 +498,20 @@ public class ClassTypeResolverTest {
|
|||||||
return new junit.framework.JUnit4TestAdapter(ClassTypeResolverTest.class);
|
return new junit.framework.JUnit4TestAdapter(ClassTypeResolverTest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ASTCompilationUnit parseAndTypeResolveForClass15(Class<?> clazz) {
|
||||||
|
return parseAndTypeResolveForClass(clazz, "1.5");
|
||||||
|
}
|
||||||
|
|
||||||
// Note: If you're using Eclipse or some other IDE to run this test, you _must_ have the regress folder in
|
// 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 classpath. Normally the IDE doesn't put source directories themselves directly in the classpath, only
|
||||||
// the output directories are in the classpath.
|
// the output directories are in the classpath.
|
||||||
private ASTCompilationUnit parseAndTypeResolveForClass(Class<?> clazz) {
|
private ASTCompilationUnit parseAndTypeResolveForClass(Class<?> clazz, String version) {
|
||||||
String sourceFile = clazz.getName().replace('.', '/') + ".java";
|
String sourceFile = clazz.getName().replace('.', '/') + ".java";
|
||||||
InputStream is = ClassTypeResolverTest.class.getClassLoader().getResourceAsStream(sourceFile);
|
InputStream is = ClassTypeResolverTest.class.getClassLoader().getResourceAsStream(sourceFile);
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
throw new IllegalArgumentException("Unable to find source file " + sourceFile + " for " + clazz);
|
throw new IllegalArgumentException("Unable to find source file " + sourceFile + " for " + clazz);
|
||||||
}
|
}
|
||||||
LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.5").getLanguageVersionHandler();
|
LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion(version).getLanguageVersionHandler();
|
||||||
ASTCompilationUnit acu = (ASTCompilationUnit) languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new InputStreamReader(is));
|
ASTCompilationUnit acu = (ASTCompilationUnit) languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new InputStreamReader(is));
|
||||||
languageVersionHandler.getSymbolFacade().start(acu);
|
languageVersionHandler.getSymbolFacade().start(acu);
|
||||||
languageVersionHandler.getTypeResolutionFacade(ClassTypeResolverTest.class.getClassLoader()).start(acu);
|
languageVersionHandler.getTypeResolutionFacade(ClassTypeResolverTest.class.getClassLoader()).start(acu);
|
||||||
|
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(); }
|
||||||
|
|
||||||
|
}
|
10
pom.xml
10
pom.xml
@ -847,6 +847,16 @@
|
|||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>jdk8-integration</id>
|
||||||
|
<activation>
|
||||||
|
<jdk>1.8</jdk>
|
||||||
|
</activation>
|
||||||
|
<modules>
|
||||||
|
<module>pmd-java8</module>
|
||||||
|
</modules>
|
||||||
|
</profile>
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>jdk9-disabled</id>
|
<id>jdk9-disabled</id>
|
||||||
<activation>
|
<activation>
|
||||||
|
Reference in New Issue
Block a user