Java: fix checkstyle issues
This commit is contained in:
@ -14,8 +14,56 @@ import java.util.logging.Logger;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.AbstractNode;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.*;
|
||||
import net.sourceforge.pmd.lang.symboltable.Scope;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAdditiveExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAndExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTArrayDimsAndInits;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTBooleanLiteral;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCastExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTConditionalAndExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTConditionalExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTConditionalOrExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTEnumDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTEqualityExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTExclusiveOrExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTInclusiveOrExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTInstanceOfExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTLiteral;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMarkerAnnotation;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMultiplicativeExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTName;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTNormalAnnotation;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTNullLiteral;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPostfixExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPreDecrementExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPreIncrementExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTReferenceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTRelationalExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTShiftExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTSingleMemberAnnotation;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTStatementExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTUnaryExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTUnaryExpressionNotPlusMinus;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
|
||||
import net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode;
|
||||
import net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter;
|
||||
import net.sourceforge.pmd.lang.java.ast.TypeNode;
|
||||
|
||||
//
|
||||
// Helpful reading:
|
||||
@ -413,8 +461,9 @@ public class ClassTypeResolver extends JavaParserVisitorAdapter {
|
||||
} else { // simple 'this' expression
|
||||
ASTClassOrInterfaceDeclaration typeDeclaration
|
||||
= currentChild.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
|
||||
if (typeDeclaration != null)
|
||||
if (typeDeclaration != null) {
|
||||
currentChild.setType(typeDeclaration.getType());
|
||||
}
|
||||
}
|
||||
|
||||
// Last token, because if 'super' is a Suffix, it'll have tokens '.' and 'super'
|
||||
@ -424,8 +473,9 @@ public class ClassTypeResolver extends JavaParserVisitorAdapter {
|
||||
} else { // simple 'super' expression
|
||||
ASTClassOrInterfaceDeclaration typeDeclaration
|
||||
= currentChild.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
|
||||
if (typeDeclaration != null && typeDeclaration.getType() != null)
|
||||
if (typeDeclaration != null && typeDeclaration.getType() != null) {
|
||||
currentChild.setType(typeDeclaration.getType().getSuperclass());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,20 +14,55 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.*;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.*;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.ThisExpression.*;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jaxen.JaxenException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTBooleanLiteral;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTLiteral;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTName;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTNullLiteral;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTReferenceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTStatementExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
|
||||
import net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode;
|
||||
import net.sourceforge.pmd.lang.java.ast.TypeNode;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.typeresolution.ClassTypeResolver;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.AnonymousInnerClass;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.ArrayListFound;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.DefaultJavaLangImport;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.EnumWithAnonymousInnerClass;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.ExtraTopLevelClass;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.InnerClass;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.Literals;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.Operators;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.Promotion;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.SuperClass;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.SuperExpression;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.ThisExpression;
|
||||
|
||||
|
||||
public class ClassTypeResolverTest {
|
||||
|
||||
@ -583,15 +618,15 @@ public class ClassTypeResolverTest {
|
||||
assertEquals(ThisExpression.class, expressions.get(index).getType());
|
||||
assertEquals(ThisExpression.class, prefixes.get(index++).getType());
|
||||
|
||||
assertEquals(ThisExprNested.class, expressions.get(index).getType());
|
||||
assertEquals(ThisExprNested.class, prefixes.get(index++).getType());
|
||||
assertEquals(ThisExpression.ThisExprNested.class, expressions.get(index).getType());
|
||||
assertEquals(ThisExpression.ThisExprNested.class, prefixes.get(index++).getType());
|
||||
|
||||
// Qualified this
|
||||
assertEquals(ThisExpression.class, expressions.get(index).getType());
|
||||
assertEquals(ThisExpression.class, prefixes.get(index++).getType());
|
||||
|
||||
assertEquals(ThisExprStaticNested.class, expressions.get(index).getType());
|
||||
assertEquals(ThisExprStaticNested.class, prefixes.get(index++).getType());
|
||||
assertEquals(ThisExpression.ThisExprStaticNested.class, expressions.get(index).getType());
|
||||
assertEquals(ThisExpression.ThisExprStaticNested.class, prefixes.get(index++).getType());
|
||||
|
||||
// Make sure we got them all
|
||||
assertEquals("All expressions not tested", index, expressions.size());
|
||||
@ -612,7 +647,7 @@ public class ClassTypeResolverTest {
|
||||
assertEquals(SuperClass.class, expressions.get(index++).getType());
|
||||
assertEquals(SuperClass.class, expressions.get(index++).getType());
|
||||
assertEquals(SuperClass.class, expressions.get(index++).getType());
|
||||
assertEquals(SuperClass.class, ((TypeNode)expressions.get(index++).jjtGetParent().jjtGetChild(1)).getType());
|
||||
assertEquals(SuperClass.class, ((TypeNode) expressions.get(index++).jjtGetParent().jjtGetChild(1)).getType());
|
||||
|
||||
assertEquals(SuperExpression.class, expressions.get(index++).getType());
|
||||
assertEquals(SuperExpression.class, expressions.get(index++).getType());
|
||||
|
@ -1,3 +1,8 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
|
||||
package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
public class SuperClass {
|
||||
|
@ -1,7 +1,14 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
|
||||
package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
public class SuperExpression extends SuperClass {
|
||||
public SuperExpression() { SuperClass a = super.s; }
|
||||
public SuperExpression() {
|
||||
SuperClass a = super.s;
|
||||
}
|
||||
|
||||
protected SuperExpression b;
|
||||
|
||||
|
@ -1,9 +1,18 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
|
||||
package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
public class ThisExpression {
|
||||
public ThisExpression() { ThisExpression a = this; }
|
||||
public ThisExpression() {
|
||||
ThisExpression a = this;
|
||||
}
|
||||
|
||||
{ ThisExpression a = this; }
|
||||
{
|
||||
ThisExpression a = this;
|
||||
}
|
||||
|
||||
public void foo() {
|
||||
ThisExpression a = this;
|
||||
|
@ -4,22 +4,31 @@
|
||||
|
||||
package net.sourceforge.pmd.typeresolution;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.*;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.*;
|
||||
import org.jaxen.JaxenException;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
|
||||
import net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.SuperClass;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.SuperExpression;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.ThisExpression;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.UsesJavaStreams;
|
||||
import net.sourceforge.pmd.typeresolution.testdata.UsesRepeatableAnnotations;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ClassTypeResolverJava8Test {
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
|
||||
package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
public class SuperClass {
|
||||
|
@ -1,8 +1,15 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
|
||||
package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
public class SuperExpression extends SuperClass {
|
||||
public void foo() {
|
||||
((Runnable) (() -> { SuperClass a = super.s; })).run();
|
||||
((Runnable) (() -> {
|
||||
SuperClass a = super.s; }))
|
||||
.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,16 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
|
||||
package net.sourceforge.pmd.typeresolution.testdata;
|
||||
|
||||
public class ThisExpression {
|
||||
|
||||
public void foo() {
|
||||
((Runnable) (() -> { ThisExpression b = this; })).run();
|
||||
((Runnable) (() -> {
|
||||
ThisExpression b = this; }))
|
||||
.run();
|
||||
}
|
||||
|
||||
public interface PrimaryThisInterface {
|
||||
|
Reference in New Issue
Block a user