pmd-apex, pmd-javascript, pmd-plsql, pmd-vm: Checkstyle fixes
This commit is contained in:
@ -43,7 +43,7 @@ import com.google.common.collect.ListMultimap;
|
||||
*
|
||||
*/
|
||||
public class ApexCRUDViolationRule extends AbstractApexRule {
|
||||
private static final Pattern p = Pattern.compile("^(string|void)$", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern VOID_OR_STRING_PATTERN = Pattern.compile("^(string|void)$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private final HashMap<String, String> varToTypeMapping = new HashMap<>();
|
||||
private final ListMultimap<String, String> typeToDMLOperationMapping = ArrayListMultimap.create();
|
||||
@ -258,7 +258,7 @@ public class ApexCRUDViolationRule extends AbstractApexRule {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkForCRUD(final AbstractApexNode<?> node, final Object data, final String CRUDMethod) {
|
||||
private void checkForCRUD(final AbstractApexNode<?> node, final Object data, final String crudMethod) {
|
||||
final ASTMethod wrappingMethod = node.getFirstParentOfType(ASTMethod.class);
|
||||
final ASTUserClass wrappingClass = node.getFirstParentOfType(ASTUserClass.class);
|
||||
|
||||
@ -274,7 +274,7 @@ public class ApexCRUDViolationRule extends AbstractApexRule {
|
||||
StringBuilder typeCheck = new StringBuilder().append(node.getNode().getDefiningType()).append(":")
|
||||
.append(type);
|
||||
|
||||
validateCRUDCheckPresent(node, data, CRUDMethod, typeCheck.toString());
|
||||
validateCRUDCheckPresent(node, data, crudMethod, typeCheck.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -310,10 +310,10 @@ public class ApexCRUDViolationRule extends AbstractApexRule {
|
||||
|
||||
}
|
||||
|
||||
private void validateCRUDCheckPresent(final AbstractApexNode<?> node, final Object data, final String CRUDMethod,
|
||||
private void validateCRUDCheckPresent(final AbstractApexNode<?> node, final Object data, final String crudMethod,
|
||||
final String typeCheck) {
|
||||
if (!typeToDMLOperationMapping.containsKey(typeCheck)) {
|
||||
if (!isProperESAPICheckForDML(typeCheck, CRUDMethod)) {
|
||||
if (!isProperESAPICheckForDML(typeCheck, crudMethod)) {
|
||||
addViolation(data, node);
|
||||
}
|
||||
} else {
|
||||
@ -321,11 +321,11 @@ public class ApexCRUDViolationRule extends AbstractApexRule {
|
||||
|
||||
List<String> dmlOperationsChecked = typeToDMLOperationMapping.get(typeCheck);
|
||||
for (String dmlOp : dmlOperationsChecked) {
|
||||
if (dmlOp.equalsIgnoreCase(CRUDMethod)) {
|
||||
if (dmlOp.equalsIgnoreCase(crudMethod)) {
|
||||
properChecksHappened = true;
|
||||
break;
|
||||
}
|
||||
if (CRUDMethod.equals(ANY)) {
|
||||
if (crudMethod.equals(ANY)) {
|
||||
properChecksHappened = true;
|
||||
break;
|
||||
}
|
||||
@ -397,7 +397,7 @@ public class ApexCRUDViolationRule extends AbstractApexRule {
|
||||
|
||||
private boolean isMethodAGetter(final ASTMethod method) {
|
||||
final boolean startsWithGet = method.getNode().getMethodInfo().getCanonicalName().startsWith("get");
|
||||
final boolean voidOrString = p
|
||||
final boolean voidOrString = VOID_OR_STRING_PATTERN
|
||||
.matcher(method.getNode().getMethodInfo().getEmitSignature().getReturnType().getApexName()).matches();
|
||||
|
||||
return (startsWithGet && !voidOrString);
|
||||
|
@ -27,7 +27,7 @@ import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
|
||||
public class ApexDangerousMethodsRule extends AbstractApexRule {
|
||||
private static final String BOOLEAN = "boolean";
|
||||
|
||||
private static final Pattern regexp = Pattern.compile("^.*?(pass|pwd|crypt|auth|session|token|saml)(?!id|user).*?$",
|
||||
private static final Pattern REGEXP = Pattern.compile("^.*?(pass|pwd|crypt|auth|session|token|saml)(?!id|user).*?$",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private static final String DISABLE_CRUD = "disableTriggerCRUDSecurity";
|
||||
@ -89,7 +89,7 @@ public class ApexDangerousMethodsRule extends AbstractApexRule {
|
||||
private void validateParameters(ASTMethodCallExpression methodCall, Object data) {
|
||||
List<ASTVariableExpression> variables = methodCall.findDescendantsOfType(ASTVariableExpression.class);
|
||||
for (ASTVariableExpression var : variables) {
|
||||
if (regexp.matcher(var.getNode().getIdentifier().value).matches()) {
|
||||
if (REGEXP.matcher(var.getNode().getIdentifier().value).matches()) {
|
||||
if (!whiteListedVariables.contains(Helper.getFQVariableName(var))) {
|
||||
addViolation(data, methodCall);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class ApexInsecureEndpointRule extends AbstractApexRule {
|
||||
private static final String SET_ENDPOINT = "setEndpoint";
|
||||
private static final Pattern PATTERN = Pattern.compile("^http://.+?$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private static final Set<String> httpEndpointStrings = new HashSet<>();
|
||||
private static final Set<String> HTTP_ENDPOINT_STRINGS = new HashSet<>();
|
||||
|
||||
public ApexInsecureEndpointRule() {
|
||||
setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" });
|
||||
@ -74,7 +74,7 @@ public class ApexInsecureEndpointRule extends AbstractApexRule {
|
||||
if (o instanceof String) {
|
||||
String literal = (String) o;
|
||||
if (PATTERN.matcher(literal).matches()) {
|
||||
httpEndpointStrings.add(Helper.getFQVariableName(variableNode));
|
||||
HTTP_ENDPOINT_STRINGS.add(Helper.getFQVariableName(variableNode));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -114,7 +114,7 @@ public class ApexInsecureEndpointRule extends AbstractApexRule {
|
||||
|
||||
ASTVariableExpression variableNode = node.getFirstChildOfType(ASTVariableExpression.class);
|
||||
if (variableNode != null) {
|
||||
if (httpEndpointStrings.contains(Helper.getFQVariableName(variableNode))) {
|
||||
if (HTTP_ENDPOINT_STRINGS.contains(Helper.getFQVariableName(variableNode))) {
|
||||
addViolation(data, variableNode);
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,9 @@ public class ApexSOQLInjectionRule extends AbstractApexRule {
|
||||
private static final String STRING = "String";
|
||||
private static final String DATABASE = "Database";
|
||||
private static final String QUERY = "query";
|
||||
private static final Pattern SELECT_PATTERN = Pattern.compile("^select[\\s]+?.+?$", Pattern.CASE_INSENSITIVE);
|
||||
private final HashSet<String> safeVariables = new HashSet<>();
|
||||
private final HashMap<String, Boolean> selectContainingVariables = new HashMap<>();
|
||||
private static final Pattern pattern = Pattern.compile("^select[\\s]+?.+?$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public ApexSOQLInjectionRule() {
|
||||
setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" });
|
||||
@ -94,7 +94,7 @@ public class ApexSOQLInjectionRule extends AbstractApexRule {
|
||||
if (left != null) {
|
||||
Object o = literal.getNode().getLiteral();
|
||||
if (o instanceof String) {
|
||||
if (pattern.matcher((String) o).matches()) {
|
||||
if (SELECT_PATTERN.matcher((String) o).matches()) {
|
||||
selectContainingVariables.put(Helper.getFQVariableName(left), Boolean.TRUE);
|
||||
} else {
|
||||
safeVariables.add(Helper.getFQVariableName(left));
|
||||
@ -141,7 +141,7 @@ public class ApexSOQLInjectionRule extends AbstractApexRule {
|
||||
|
||||
Object o = literal.getNode().getLiteral();
|
||||
if (o instanceof String) {
|
||||
if (pattern.matcher((String) o).matches()) {
|
||||
if (SELECT_PATTERN.matcher((String) o).matches()) {
|
||||
if (!isSafeVariable) {
|
||||
// select literal + other unsafe vars
|
||||
selectContainingVariables.put(Helper.getFQVariableName(var), Boolean.FALSE);
|
||||
|
@ -40,7 +40,7 @@ public class ApexXSSFromURLParamRule extends AbstractApexRule {
|
||||
private static final String[] DOUBLE_VALUEOF = new String[] { "Double", "valueOf" };
|
||||
private static final String[] STRING_ISEMPTY = new String[] { "String", "isEmpty" };
|
||||
|
||||
private static final Set<String> urlParameterString = new HashSet<>();
|
||||
private static final Set<String> URL_PARAMETER_STRINGS = new HashSet<>();
|
||||
|
||||
public ApexXSSFromURLParamRule() {
|
||||
setProperty(CODECLIMATE_CATEGORIES, new String[] { "Security" });
|
||||
@ -91,7 +91,7 @@ public class ApexXSSFromURLParamRule extends AbstractApexRule {
|
||||
List<ASTVariableExpression> nodes = node.findChildrenOfType(ASTVariableExpression.class);
|
||||
|
||||
for (ASTVariableExpression varExpression : nodes) {
|
||||
if (urlParameterString.contains(Helper.getFQVariableName(varExpression))) {
|
||||
if (URL_PARAMETER_STRINGS.contains(Helper.getFQVariableName(varExpression))) {
|
||||
addViolation(data, nodes.get(0));
|
||||
}
|
||||
}
|
||||
@ -133,7 +133,7 @@ public class ApexXSSFromURLParamRule extends AbstractApexRule {
|
||||
ASTVariableExpression left = node.getFirstChildOfType(ASTVariableExpression.class);
|
||||
|
||||
if (left != null) {
|
||||
urlParameterString.add(Helper.getFQVariableName(left));
|
||||
URL_PARAMETER_STRINGS.add(Helper.getFQVariableName(left));
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ public class ApexXSSFromURLParamRule extends AbstractApexRule {
|
||||
return;
|
||||
}
|
||||
|
||||
if (urlParameterString.contains(Helper.getFQVariableName(variable))) {
|
||||
if (URL_PARAMETER_STRINGS.contains(Helper.getFQVariableName(variable))) {
|
||||
if (!isEscapingMethod(methodNode)) {
|
||||
addViolation(data, variable);
|
||||
}
|
||||
@ -190,7 +190,7 @@ public class ApexXSSFromURLParamRule extends AbstractApexRule {
|
||||
// Look for: foo = bar;
|
||||
final ASTVariableExpression right = reverseOrder ? nodes.get(0) : nodes.get(1);
|
||||
|
||||
if (urlParameterString.contains(Helper.getFQVariableName(right))) {
|
||||
if (URL_PARAMETER_STRINGS.contains(Helper.getFQVariableName(right))) {
|
||||
addViolation(data, right);
|
||||
}
|
||||
}
|
||||
@ -215,7 +215,7 @@ public class ApexXSSFromURLParamRule extends AbstractApexRule {
|
||||
final List<ASTVariableExpression> nodes = node.findChildrenOfType(ASTVariableExpression.class);
|
||||
for (ASTVariableExpression n : nodes) {
|
||||
|
||||
if (urlParameterString.contains(Helper.getFQVariableName(n))) {
|
||||
if (URL_PARAMETER_STRINGS.contains(Helper.getFQVariableName(n))) {
|
||||
addViolation(data, n);
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ public class VariableNamingConventionsRule extends AbstractApexRule {
|
||||
String varName = node.getImage();
|
||||
|
||||
// Skip on null (with exception classes) and serialVersionUID
|
||||
if (varName == null || varName.equals("serialVersionUID")) {
|
||||
if (varName == null || "serialVersionUID".equals(varName)) {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,8 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ApexParserTestHelpers {
|
||||
private ApexParserTestHelpers() { }
|
||||
|
||||
public static ApexNode<Compilation> parse(String code) {
|
||||
ApexParser parser = new ApexParser(new ApexParserOptions());
|
||||
Reader reader = new StringReader(code);
|
||||
|
@ -20,7 +20,7 @@ import net.sourceforge.pmd.typeresolution.testdata.UsesJavaStreams;
|
||||
public class InterfaceMethodTest {
|
||||
|
||||
@Test
|
||||
public void should_not_fail() {
|
||||
public void shouldNotFail() {
|
||||
ASTCompilationUnit acu = parseAndTypeResolveForClass(UsesJavaStreams.class);
|
||||
}
|
||||
|
||||
|
@ -19,19 +19,15 @@ import net.sourceforge.pmd.typeresolution.testdata.UsesRepeatableAnnotations;
|
||||
public class ClassTypeResolverJava8Test {
|
||||
|
||||
@Test
|
||||
public void interface_method_should_be_parseable() {
|
||||
public void interfaceMethodShouldBeParseable() {
|
||||
ASTCompilationUnit acu = parseAndTypeResolveForClass18(UsesJavaStreams.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeatable_annotations_method_should_be_parseable() {
|
||||
public void repeatableAnnotationsMethodShouldBeParseable() {
|
||||
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");
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase {
|
||||
*/
|
||||
@Test
|
||||
public void testLineNumbers() {
|
||||
String SOURCE_CODE = "function a() {" + PMD.EOL + " alert('hello');" + PMD.EOL + "}" + PMD.EOL;
|
||||
final String SOURCE_CODE = "function a() {" + PMD.EOL + " alert('hello');" + PMD.EOL + "}" + PMD.EOL;
|
||||
EcmascriptNode<AstRoot> node = parse(SOURCE_CODE);
|
||||
assertEquals(1, node.getBeginLine());
|
||||
assertEquals(1, node.getBeginColumn());
|
||||
|
@ -107,7 +107,7 @@ public class TypeSet {
|
||||
|
||||
public static class VoidResolver implements Resolver {
|
||||
public Class<?> resolve(String name) throws ClassNotFoundException {
|
||||
if (name.equals("void")) {
|
||||
if ("void".equals(name)) {
|
||||
return void.class;
|
||||
}
|
||||
throw new ClassNotFoundException();
|
||||
|
@ -30,6 +30,7 @@ import org.apache.commons.lang3.text.StrBuilder;
|
||||
* @version $Id: NodeUtils.java 687386 2008-08-20 16:57:07Z nbubna $
|
||||
*/
|
||||
public class NodeUtils {
|
||||
private NodeUtils() { }
|
||||
|
||||
/**
|
||||
* Collect all the <SPECIAL_TOKEN>s that are carried along with a token.
|
||||
|
@ -52,9 +52,9 @@ public class TokenMgrError extends RuntimeException {
|
||||
errorCode = reason;
|
||||
}
|
||||
|
||||
public TokenMgrError(final boolean EOFSeen, final int lexState, final int errorLine, final int errorColumn,
|
||||
public TokenMgrError(final boolean eofSeen, final int lexState, final int errorLine, final int errorColumn,
|
||||
final String errorAfter, final char curChar, final int reason) {
|
||||
this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
|
||||
this(lexicalError(eofSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,10 +115,10 @@ public class TokenMgrError extends RuntimeException {
|
||||
* before this error occured curchar : the offending character Note: You can
|
||||
* customize the lexical error message by modifying this method.
|
||||
*/
|
||||
protected static String LexicalError(final boolean EOFSeen, final int lexState, final int errorLine,
|
||||
protected static String lexicalError(final boolean eofSeen, final int lexState, final int errorLine,
|
||||
final int errorColumn, final String errorAfter, final char curChar) {
|
||||
return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: "
|
||||
+ (EOFSeen ? "<EOF> "
|
||||
+ (eofSeen ? "<EOF> "
|
||||
: ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ")
|
||||
+ "after : \"" + addEscapes(errorAfter) + "\"");
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import net.sourceforge.pmd.lang.vm.directive.Parse;
|
||||
import net.sourceforge.pmd.lang.vm.directive.Stop;
|
||||
|
||||
public class DirectiveMapper {
|
||||
private DirectiveMapper() { }
|
||||
|
||||
private static final Map<String, Directive> DIRECTIVE_MAP = new HashMap<>();
|
||||
|
||||
|
@ -33,6 +33,7 @@ import net.sourceforge.pmd.lang.vm.directive.Directive;
|
||||
* @since 1.5
|
||||
*/
|
||||
public class LogUtil {
|
||||
private LogUtil() { }
|
||||
|
||||
/**
|
||||
* Creates a string that formats the template filename with line number and
|
||||
@ -65,7 +66,7 @@ public class LogUtil {
|
||||
* Column number withing the file at linenum
|
||||
*/
|
||||
public static final String formatFileString(String template, final int linenum, final int colnum) {
|
||||
if (template == null || template.equals("")) {
|
||||
if (template == null || "".equals(template)) {
|
||||
template = "<unknown template>";
|
||||
}
|
||||
return template + "[line " + linenum + ", column " + colnum + "]";
|
||||
|
@ -108,7 +108,7 @@ public final class VelocityCharStream implements CharStream {
|
||||
this(dstream, startline, startcolumn, 4096);
|
||||
}
|
||||
|
||||
private void ExpandBuff(boolean wrapAround) {
|
||||
private void expandBuff(boolean wrapAround) {
|
||||
char[] newbuffer = new char[bufsize + nextBufExpand];
|
||||
int[] newbufline = new int[bufsize + nextBufExpand];
|
||||
int[] newbufcolumn = new int[bufsize + nextBufExpand];
|
||||
@ -152,7 +152,7 @@ public final class VelocityCharStream implements CharStream {
|
||||
tokenBegin = 0;
|
||||
}
|
||||
|
||||
private void FillBuff() throws java.io.IOException {
|
||||
private void fillBuff() throws java.io.IOException {
|
||||
if (maxNextCharInd == available) {
|
||||
if (available == bufsize) {
|
||||
if (tokenBegin > nextBufExpand) {
|
||||
@ -163,12 +163,12 @@ public final class VelocityCharStream implements CharStream {
|
||||
bufpos = 0;
|
||||
maxNextCharInd = 0;
|
||||
} else {
|
||||
ExpandBuff(false);
|
||||
expandBuff(false);
|
||||
}
|
||||
} else if (available > tokenBegin) {
|
||||
available = bufsize;
|
||||
} else if ((tokenBegin - available) < nextBufExpand) {
|
||||
ExpandBuff(true);
|
||||
expandBuff(true);
|
||||
} else {
|
||||
available = tokenBegin;
|
||||
}
|
||||
@ -206,7 +206,7 @@ public final class VelocityCharStream implements CharStream {
|
||||
return c;
|
||||
}
|
||||
|
||||
private void UpdateLineColumn(char c) {
|
||||
private void updateLineColumn(char c) {
|
||||
column++;
|
||||
|
||||
if (prevCharIsLF) {
|
||||
@ -264,7 +264,7 @@ public final class VelocityCharStream implements CharStream {
|
||||
|
||||
bufpos++;
|
||||
if (bufpos >= maxNextCharInd) {
|
||||
FillBuff();
|
||||
fillBuff();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -272,7 +272,7 @@ public final class VelocityCharStream implements CharStream {
|
||||
*/
|
||||
char c = buffer[bufpos];
|
||||
|
||||
UpdateLineColumn(c);
|
||||
updateLineColumn(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -347,7 +347,7 @@ public final class VelocityCharStream implements CharStream {
|
||||
* @param startcolumn
|
||||
* @param buffersize
|
||||
*/
|
||||
public void ReInit(java.io.Reader dstream, int startline, int startcolumn, int buffersize) {
|
||||
public void reInit(java.io.Reader dstream, int startline, int startcolumn, int buffersize) {
|
||||
inputStream = dstream;
|
||||
line = startline;
|
||||
column = startcolumn - 1;
|
||||
@ -373,8 +373,8 @@ public final class VelocityCharStream implements CharStream {
|
||||
* @param startline
|
||||
* @param startcolumn
|
||||
*/
|
||||
public void ReInit(java.io.Reader dstream, int startline, int startcolumn) {
|
||||
ReInit(dstream, startline, startcolumn, 4096);
|
||||
public void reInit(java.io.Reader dstream, int startline, int startcolumn) {
|
||||
reInit(dstream, startline, startcolumn, 4096);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -383,8 +383,8 @@ public final class VelocityCharStream implements CharStream {
|
||||
* @param startcolumn
|
||||
* @param buffersize
|
||||
*/
|
||||
public void ReInit(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) {
|
||||
ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
|
||||
public void reInit(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) {
|
||||
reInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -392,8 +392,8 @@ public final class VelocityCharStream implements CharStream {
|
||||
* @param startline
|
||||
* @param startcolumn
|
||||
*/
|
||||
public void ReInit(java.io.InputStream dstream, int startline, int startcolumn) {
|
||||
ReInit(dstream, startline, startcolumn, 4096);
|
||||
public void reInit(java.io.InputStream dstream, int startline, int startcolumn) {
|
||||
reInit(dstream, startline, startcolumn, 4096);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user