Introduce end-of-line normalization

References pmd/build-tools#2
This commit is contained in:
Andreas Dangel
2017-02-02 20:08:53 +01:00
parent ffb00b86e1
commit d92688a07d
391 changed files with 42076 additions and 42063 deletions

13
.gitattributes vendored Normal file
View File

@ -0,0 +1,13 @@
* text=auto
*.java text
*.xml text
*.jjt text
*.jj text
*.g4 text
*.md text
*.sh text eol=lf
*.bat text eol=crlf
*.png -text
*.jpg -text
*.svgz -text
*.jar -text

View File

@ -1,57 +1,57 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex; package net.sourceforge.pmd.lang.apex;
import java.io.Writer; import java.io.Writer;
import net.sourceforge.pmd.lang.AbstractLanguageVersionHandler; import net.sourceforge.pmd.lang.AbstractLanguageVersionHandler;
import net.sourceforge.pmd.lang.Parser; import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.VisitorStarter; import net.sourceforge.pmd.lang.VisitorStarter;
import net.sourceforge.pmd.lang.XPathHandler; import net.sourceforge.pmd.lang.XPathHandler;
import net.sourceforge.pmd.lang.apex.ast.ApexNode; import net.sourceforge.pmd.lang.apex.ast.ApexNode;
import net.sourceforge.pmd.lang.apex.ast.DumpFacade; import net.sourceforge.pmd.lang.apex.ast.DumpFacade;
import net.sourceforge.pmd.lang.apex.rule.ApexRuleViolationFactory; import net.sourceforge.pmd.lang.apex.rule.ApexRuleViolationFactory;
import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.AbstractASTXPathHandler; import net.sourceforge.pmd.lang.ast.xpath.AbstractASTXPathHandler;
import net.sourceforge.pmd.lang.rule.RuleViolationFactory; import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
import net.sf.saxon.sxpath.IndependentContext; import net.sf.saxon.sxpath.IndependentContext;
public class ApexHandler extends AbstractLanguageVersionHandler { public class ApexHandler extends AbstractLanguageVersionHandler {
@Override @Override
public XPathHandler getXPathHandler() { public XPathHandler getXPathHandler() {
return new AbstractASTXPathHandler() { return new AbstractASTXPathHandler() {
public void initialize() { public void initialize() {
} }
public void initialize(IndependentContext context) { public void initialize(IndependentContext context) {
} }
}; };
} }
public RuleViolationFactory getRuleViolationFactory() { public RuleViolationFactory getRuleViolationFactory() {
return ApexRuleViolationFactory.INSTANCE; return ApexRuleViolationFactory.INSTANCE;
} }
@Override @Override
public ParserOptions getDefaultParserOptions() { public ParserOptions getDefaultParserOptions() {
return new ApexParserOptions(); return new ApexParserOptions();
} }
public Parser getParser(ParserOptions parserOptions) { public Parser getParser(ParserOptions parserOptions) {
return new ApexParser(parserOptions); return new ApexParser(parserOptions);
} }
@Override @Override
public VisitorStarter getDumpFacade(Writer writer, String prefix, boolean recurse) { public VisitorStarter getDumpFacade(Writer writer, String prefix, boolean recurse) {
return new VisitorStarter() { return new VisitorStarter() {
public void start(Node rootNode) { public void start(Node rootNode) {
new DumpFacade().initializeWith(writer, prefix, recurse, (ApexNode<?>) rootNode); new DumpFacade().initializeWith(writer, prefix, recurse, (ApexNode<?>) rootNode);
} }
}; };
} }
} }

View File

@ -1,43 +1,43 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex; package net.sourceforge.pmd.lang.apex;
import java.io.Reader; import java.io.Reader;
import java.util.Map; import java.util.Map;
import net.sourceforge.pmd.lang.AbstractParser; import net.sourceforge.pmd.lang.AbstractParser;
import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.TokenManager; import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.ParseException;
/** /**
* Adapter for the Apex jorje parser * Adapter for the Apex jorje parser
*/ */
public class ApexParser extends AbstractParser { public class ApexParser extends AbstractParser {
private net.sourceforge.pmd.lang.apex.ast.ApexParser apexParser; private net.sourceforge.pmd.lang.apex.ast.ApexParser apexParser;
public ApexParser(ParserOptions parserOptions) { public ApexParser(ParserOptions parserOptions) {
super(parserOptions); super(parserOptions);
apexParser = new net.sourceforge.pmd.lang.apex.ast.ApexParser((ApexParserOptions) parserOptions); apexParser = new net.sourceforge.pmd.lang.apex.ast.ApexParser((ApexParserOptions) parserOptions);
} }
@Override @Override
public TokenManager createTokenManager(Reader source) { public TokenManager createTokenManager(Reader source) {
return null; return null;
} }
public boolean canParse() { public boolean canParse() {
return true; return true;
} }
public Node parse(String fileName, Reader source) throws ParseException { public Node parse(String fileName, Reader source) throws ParseException {
return apexParser.parse(source); return apexParser.parse(source);
} }
public Map<Integer, String> getSuppressMap() { public Map<Integer, String> getSuppressMap() {
return apexParser.getSuppressMap(); return apexParser.getSuppressMap();
} }
} }

View File

@ -1,33 +1,33 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex; package net.sourceforge.pmd.lang.apex;
import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.util.StringUtil; import net.sourceforge.pmd.util.StringUtil;
public class ApexParserOptions extends ParserOptions { public class ApexParserOptions extends ParserOptions {
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = super.hashCode();
result = prime * result + (1237); result = prime * result + (1237);
result = prime * result + (1237); result = prime * result + (1237);
result = prime * result; result = prime * result;
return result; return result;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj == null || getClass() != obj.getClass()) { if (obj == null || getClass() != obj.getClass()) {
return false; return false;
} }
final ApexParserOptions that = (ApexParserOptions) obj; final ApexParserOptions that = (ApexParserOptions) obj;
return StringUtil.isSame(this.suppressMarker, that.suppressMarker, false, false, false); return StringUtil.isSame(this.suppressMarker, that.suppressMarker, false, false, false);
} }
} }

View File

@ -1,141 +1,141 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.ast; package net.sourceforge.pmd.lang.apex.ast;
import net.sourceforge.pmd.lang.ast.AbstractNode; import net.sourceforge.pmd.lang.ast.AbstractNode;
import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.SourceCodePositioner; import net.sourceforge.pmd.lang.ast.SourceCodePositioner;
import apex.jorje.data.Loc; import apex.jorje.data.Loc;
import apex.jorje.data.Loc.RealLoc; import apex.jorje.data.Loc.RealLoc;
import apex.jorje.semantic.ast.AstNode; import apex.jorje.semantic.ast.AstNode;
import apex.jorje.semantic.exception.UnexpectedCodePathException; import apex.jorje.semantic.exception.UnexpectedCodePathException;
public abstract class AbstractApexNode<T extends AstNode> extends AbstractNode implements ApexNode<T> { public abstract class AbstractApexNode<T extends AstNode> extends AbstractNode implements ApexNode<T> {
protected final T node; protected final T node;
public AbstractApexNode(T node) { public AbstractApexNode(T node) {
super(node.getClass().hashCode()); super(node.getClass().hashCode());
this.node = node; this.node = node;
} }
void calculateLineNumbers(SourceCodePositioner positioner) { void calculateLineNumbers(SourceCodePositioner positioner) {
if (!hasRealLoc()) { if (!hasRealLoc()) {
return; return;
} }
RealLoc loc = (RealLoc) node.getLoc(); RealLoc loc = (RealLoc) node.getLoc();
int startOffset = loc.startIndex; int startOffset = loc.startIndex;
int endOffset = loc.endIndex; int endOffset = loc.endIndex;
// end column will be interpreted as inclusive, while endOffset/endIndex // end column will be interpreted as inclusive, while endOffset/endIndex
// is exclusive // is exclusive
endOffset -= 1; endOffset -= 1;
this.beginLine = positioner.lineNumberFromOffset(startOffset); this.beginLine = positioner.lineNumberFromOffset(startOffset);
this.beginColumn = positioner.columnFromOffset(this.beginLine, startOffset); this.beginColumn = positioner.columnFromOffset(this.beginLine, startOffset);
this.endLine = positioner.lineNumberFromOffset(endOffset); this.endLine = positioner.lineNumberFromOffset(endOffset);
this.endColumn = positioner.columnFromOffset(this.endLine, endOffset); this.endColumn = positioner.columnFromOffset(this.endLine, endOffset);
if (this.endColumn < 0) { if (this.endColumn < 0) {
this.endColumn = 0; this.endColumn = 0;
} }
} }
@Override @Override
public int getBeginLine() { public int getBeginLine() {
if (this.beginLine > 0) { if (this.beginLine > 0) {
return this.beginLine; return this.beginLine;
} }
Node parent = jjtGetParent(); Node parent = jjtGetParent();
if (parent != null) { if (parent != null) {
return parent.getBeginLine(); return parent.getBeginLine();
} }
throw new RuntimeException("Unable to determine beginning line of Node."); throw new RuntimeException("Unable to determine beginning line of Node.");
} }
@Override @Override
public int getBeginColumn() { public int getBeginColumn() {
if (this.beginColumn > 0) { if (this.beginColumn > 0) {
return this.beginColumn; return this.beginColumn;
} }
Node parent = jjtGetParent(); Node parent = jjtGetParent();
if (parent != null) { if (parent != null) {
return parent.getBeginColumn(); return parent.getBeginColumn();
} }
throw new RuntimeException("Unable to determine beginning column of Node."); throw new RuntimeException("Unable to determine beginning column of Node.");
} }
@Override @Override
public int getEndLine() { public int getEndLine() {
if (this.endLine > 0) { if (this.endLine > 0) {
return this.endLine; return this.endLine;
} }
Node parent = jjtGetParent(); Node parent = jjtGetParent();
if (parent != null) { if (parent != null) {
return parent.getEndLine(); return parent.getEndLine();
} }
throw new RuntimeException("Unable to determine ending line of Node."); throw new RuntimeException("Unable to determine ending line of Node.");
} }
@Override @Override
public int getEndColumn() { public int getEndColumn() {
if (this.endColumn > 0) { if (this.endColumn > 0) {
return this.endColumn; return this.endColumn;
} }
Node parent = jjtGetParent(); Node parent = jjtGetParent();
if (parent != null) { if (parent != null) {
return parent.getEndColumn(); return parent.getEndColumn();
} }
throw new RuntimeException("Unable to determine ending column of Node."); throw new RuntimeException("Unable to determine ending column of Node.");
} }
/** /**
* Accept the visitor. * * Accept the visitor. *
*/ */
public Object childrenAccept(ApexParserVisitor visitor, Object data) { public Object childrenAccept(ApexParserVisitor visitor, Object data) {
if (children != null) { if (children != null) {
for (int i = 0; i < children.length; ++i) { for (int i = 0; i < children.length; ++i) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// we know that the children here are all ApexNodes // we know that the children here are all ApexNodes
ApexNode<T> apexNode = (ApexNode<T>) children[i]; ApexNode<T> apexNode = (ApexNode<T>) children[i];
apexNode.jjtAccept(visitor, data); apexNode.jjtAccept(visitor, data);
} }
} }
return data; return data;
} }
public T getNode() { public T getNode() {
return node; return node;
} }
protected boolean hasRealLoc() { protected boolean hasRealLoc() {
try { try {
Loc loc = node.getLoc(); Loc loc = node.getLoc();
return loc instanceof RealLoc; return loc instanceof RealLoc;
} catch (UnexpectedCodePathException e) { } catch (UnexpectedCodePathException e) {
return false; return false;
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
// bug in apex-jorje? happens on some ReferenceExpression nodes // bug in apex-jorje? happens on some ReferenceExpression nodes
return false; return false;
} catch (NullPointerException e) { } catch (NullPointerException e) {
// bug in apex-jorje? // bug in apex-jorje?
return false; return false;
} }
} }
@Override @Override
public String toString() { public String toString() {
return this.getClass().getSimpleName().replaceFirst("^AST", ""); return this.getClass().getSimpleName().replaceFirst("^AST", "");
} }
public String getLocation() { public String getLocation() {
if (hasRealLoc()) { if (hasRealLoc()) {
return String.valueOf(node.getLoc()); return String.valueOf(node.getLoc());
} else { } else {
return "no location"; return "no location";
} }
} }
} }

View File

@ -1,27 +1,27 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.ast; package net.sourceforge.pmd.lang.apex.ast;
import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.Node;
import apex.jorje.semantic.ast.AstNode; import apex.jorje.semantic.ast.AstNode;
public interface ApexNode<T extends AstNode> extends Node { public interface ApexNode<T extends AstNode> extends Node {
/** /**
* Accept the visitor. * * Accept the visitor. *
*/ */
Object jjtAccept(ApexParserVisitor visitor, Object data); Object jjtAccept(ApexParserVisitor visitor, Object data);
/** /**
* Accept the visitor. * * Accept the visitor. *
*/ */
Object childrenAccept(ApexParserVisitor visitor, Object data); Object childrenAccept(ApexParserVisitor visitor, Object data);
/** /**
* Get the underlying AST node. * Get the underlying AST node.
*/ */
T getNode(); T getNode();
} }

View File

@ -1,97 +1,97 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.ast; package net.sourceforge.pmd.lang.apex.ast;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import net.sourceforge.pmd.lang.apex.ApexParserOptions; import net.sourceforge.pmd.lang.apex.ApexParserOptions;
import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.ParseException;
import apex.jorje.semantic.ast.compilation.Compilation; import apex.jorje.semantic.ast.compilation.Compilation;
import apex.jorje.semantic.ast.compilation.UserClass; import apex.jorje.semantic.ast.compilation.UserClass;
import apex.jorje.semantic.ast.compilation.UserEnum; import apex.jorje.semantic.ast.compilation.UserEnum;
import apex.jorje.semantic.ast.compilation.UserInterface; import apex.jorje.semantic.ast.compilation.UserInterface;
import apex.jorje.semantic.ast.compilation.UserTrigger; import apex.jorje.semantic.ast.compilation.UserTrigger;
import apex.jorje.semantic.ast.visitor.AdditionalPassScope; import apex.jorje.semantic.ast.visitor.AdditionalPassScope;
import apex.jorje.semantic.ast.visitor.AstVisitor; import apex.jorje.semantic.ast.visitor.AstVisitor;
public class ApexParser { public class ApexParser {
protected final ApexParserOptions parserOptions; protected final ApexParserOptions parserOptions;
private Map<Integer, String> suppressMap; private Map<Integer, String> suppressMap;
private String suppressMarker = "NOPMD"; private String suppressMarker = "NOPMD";
public ApexParser(ApexParserOptions parserOptions) { public ApexParser(ApexParserOptions parserOptions) {
this.parserOptions = parserOptions; this.parserOptions = parserOptions;
if (parserOptions.getSuppressMarker() != null) { if (parserOptions.getSuppressMarker() != null) {
suppressMarker = parserOptions.getSuppressMarker(); suppressMarker = parserOptions.getSuppressMarker();
} }
} }
public Compilation parseApex(final String sourceCode) throws ParseException { public Compilation parseApex(final String sourceCode) throws ParseException {
TopLevelVisitor visitor = new TopLevelVisitor(); TopLevelVisitor visitor = new TopLevelVisitor();
CompilerService.INSTANCE.visitAstFromString(sourceCode, visitor); CompilerService.INSTANCE.visitAstFromString(sourceCode, visitor);
Compilation astRoot = visitor.getTopLevel(); Compilation astRoot = visitor.getTopLevel();
return astRoot; return astRoot;
} }
public ApexNode<Compilation> parse(final Reader reader) { public ApexNode<Compilation> parse(final Reader reader) {
try { try {
final String sourceCode = IOUtils.toString(reader); final String sourceCode = IOUtils.toString(reader);
final Compilation astRoot = parseApex(sourceCode); final Compilation astRoot = parseApex(sourceCode);
final ApexTreeBuilder treeBuilder = new ApexTreeBuilder(sourceCode); final ApexTreeBuilder treeBuilder = new ApexTreeBuilder(sourceCode);
suppressMap = new HashMap<>(); suppressMap = new HashMap<>();
if (astRoot == null) { if (astRoot == null) {
throw new ParseException("Couldn't parse the source - there is not root node - Syntax Error??"); throw new ParseException("Couldn't parse the source - there is not root node - Syntax Error??");
} }
ApexNode<Compilation> tree = treeBuilder.build(astRoot); ApexNode<Compilation> tree = treeBuilder.build(astRoot);
return tree; return tree;
} catch (IOException e) { } catch (IOException e) {
throw new ParseException(e); throw new ParseException(e);
} }
} }
public Map<Integer, String> getSuppressMap() { public Map<Integer, String> getSuppressMap() {
return suppressMap; return suppressMap;
} }
private class TopLevelVisitor extends AstVisitor<AdditionalPassScope> { private class TopLevelVisitor extends AstVisitor<AdditionalPassScope> {
Compilation topLevel; Compilation topLevel;
public Compilation getTopLevel() { public Compilation getTopLevel() {
return topLevel; return topLevel;
} }
@Override @Override
public void visitEnd(UserClass node, AdditionalPassScope scope) { public void visitEnd(UserClass node, AdditionalPassScope scope) {
topLevel = node; topLevel = node;
} }
@Override @Override
public void visitEnd(UserEnum node, AdditionalPassScope scope) { public void visitEnd(UserEnum node, AdditionalPassScope scope) {
topLevel = node; topLevel = node;
} }
@Override @Override
public void visitEnd(UserInterface node, AdditionalPassScope scope) { public void visitEnd(UserInterface node, AdditionalPassScope scope) {
topLevel = node; topLevel = node;
} }
@Override @Override
public void visitEnd(UserTrigger node, AdditionalPassScope scope) { public void visitEnd(UserTrigger node, AdditionalPassScope scope) {
topLevel = node; topLevel = node;
} }
} }
} }

View File

@ -1,32 +1,32 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.rule; package net.sourceforge.pmd.lang.apex.rule;
import java.util.List; import java.util.List;
import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.stat.StatisticalRule; import net.sourceforge.pmd.lang.rule.stat.StatisticalRule;
import net.sourceforge.pmd.lang.rule.stat.StatisticalRuleHelper; import net.sourceforge.pmd.lang.rule.stat.StatisticalRuleHelper;
import net.sourceforge.pmd.stat.DataPoint; import net.sourceforge.pmd.stat.DataPoint;
public abstract class AbstractStatisticalApexRule extends AbstractApexRule implements StatisticalRule { public abstract class AbstractStatisticalApexRule extends AbstractApexRule implements StatisticalRule {
private final StatisticalRuleHelper helper = new StatisticalRuleHelper(this); private final StatisticalRuleHelper helper = new StatisticalRuleHelper(this);
public void addDataPoint(DataPoint point) { public void addDataPoint(DataPoint point) {
helper.addDataPoint(point); helper.addDataPoint(point);
} }
public Object[] getViolationParameters(DataPoint point) { public Object[] getViolationParameters(DataPoint point) {
return null; return null;
} }
@Override @Override
public void apply(List<? extends Node> nodes, RuleContext ctx) { public void apply(List<? extends Node> nodes, RuleContext ctx) {
super.apply(nodes, ctx); super.apply(nodes, ctx);
helper.apply(ctx); helper.apply(ctx);
} }
} }

View File

@ -1,43 +1,43 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.rule; package net.sourceforge.pmd.lang.apex.rule;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Stack; import java.util.Stack;
import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.apex.ast.ApexNode; import net.sourceforge.pmd.lang.apex.ast.ApexNode;
import net.sourceforge.pmd.lang.apex.ast.ApexParserVisitor; import net.sourceforge.pmd.lang.apex.ast.ApexParserVisitor;
import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor; import net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor;
import net.sourceforge.pmd.lang.rule.XPathRule; import net.sourceforge.pmd.lang.rule.XPathRule;
public class ApexRuleChainVisitor extends AbstractRuleChainVisitor { public class ApexRuleChainVisitor extends AbstractRuleChainVisitor {
protected void indexNodes(List<Node> nodes, RuleContext ctx) { protected void indexNodes(List<Node> nodes, RuleContext ctx) {
Stack<Node> stack = new Stack<>(); Stack<Node> stack = new Stack<>();
stack.addAll(nodes); stack.addAll(nodes);
Collections.reverse(stack); Collections.reverse(stack);
while (!stack.isEmpty()) { while (!stack.isEmpty()) {
Node node = stack.pop(); Node node = stack.pop();
indexNode(node); indexNode(node);
if (node.jjtGetNumChildren() > 0) { if (node.jjtGetNumChildren() > 0) {
for (int i = node.jjtGetNumChildren() - 1; i >= 0; i--) { for (int i = node.jjtGetNumChildren() - 1; i >= 0; i--) {
stack.push(node.jjtGetChild(i)); stack.push(node.jjtGetChild(i));
} }
} }
} }
} }
protected void visit(Rule rule, Node node, RuleContext ctx) { protected void visit(Rule rule, Node node, RuleContext ctx) {
if (rule instanceof XPathRule) { if (rule instanceof XPathRule) {
((XPathRule) rule).evaluate(node, ctx); ((XPathRule) rule).evaluate(node, ctx);
} else { } else {
((ApexNode<?>) node).jjtAccept((ApexParserVisitor) rule, ctx); ((ApexNode<?>) node).jjtAccept((ApexParserVisitor) rule, ctx);
} }
} }
} }

View File

@ -1,32 +1,32 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.rule; package net.sourceforge.pmd.lang.apex.rule;
import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.apex.ast.ApexNode; import net.sourceforge.pmd.lang.apex.ast.ApexNode;
import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory;
import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; import net.sourceforge.pmd.lang.rule.ParametricRuleViolation;
public final class ApexRuleViolationFactory extends AbstractRuleViolationFactory { public final class ApexRuleViolationFactory extends AbstractRuleViolationFactory {
public static final ApexRuleViolationFactory INSTANCE = new ApexRuleViolationFactory(); public static final ApexRuleViolationFactory INSTANCE = new ApexRuleViolationFactory();
private ApexRuleViolationFactory() { private ApexRuleViolationFactory() {
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) {
return new ParametricRuleViolation<>(rule, ruleContext, (ApexNode) node, message); return new ParametricRuleViolation<>(rule, ruleContext, (ApexNode) node, message);
} }
protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message,
int beginLine, int endLine) { int beginLine, int endLine) {
return null; // FIXME return null; // FIXME
} }
} }

View File

@ -1,23 +1,23 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.rule; package net.sourceforge.pmd.lang.apex.rule;
import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.apex.ApexLanguageModule; import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
import net.sourceforge.pmd.lang.apex.ApexParserOptions; import net.sourceforge.pmd.lang.apex.ApexParserOptions;
import net.sourceforge.pmd.lang.rule.XPathRule; import net.sourceforge.pmd.lang.rule.XPathRule;
public class ApexXPathRule extends XPathRule { public class ApexXPathRule extends XPathRule {
public ApexXPathRule() { public ApexXPathRule() {
super.setLanguage(LanguageRegistry.getLanguage(ApexLanguageModule.NAME)); super.setLanguage(LanguageRegistry.getLanguage(ApexLanguageModule.NAME));
} }
@Override @Override
public ParserOptions getParserOptions() { public ParserOptions getParserOptions() {
return new ApexParserOptions(); return new ApexParserOptions();
} }
} }

View File

@ -1,47 +1,47 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.rule.complexity; package net.sourceforge.pmd.lang.apex.rule.complexity;
import net.sourceforge.pmd.lang.apex.ast.ASTIfBlockStatement; import net.sourceforge.pmd.lang.apex.ast.ASTIfBlockStatement;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
import net.sourceforge.pmd.lang.rule.properties.IntegerProperty; import net.sourceforge.pmd.lang.rule.properties.IntegerProperty;
public class AvoidDeeplyNestedIfStmtsRule extends AbstractApexRule { public class AvoidDeeplyNestedIfStmtsRule extends AbstractApexRule {
private int depth; private int depth;
private int depthLimit; private int depthLimit;
private static final IntegerProperty PROBLEM_DEPTH_DESCRIPTOR = new IntegerProperty("problemDepth", private static final IntegerProperty PROBLEM_DEPTH_DESCRIPTOR = new IntegerProperty("problemDepth",
"The if statement depth reporting threshold", 1, 25, 3, 1.0f); "The if statement depth reporting threshold", 1, 25, 3, 1.0f);
public AvoidDeeplyNestedIfStmtsRule() { public AvoidDeeplyNestedIfStmtsRule() {
definePropertyDescriptor(PROBLEM_DEPTH_DESCRIPTOR); definePropertyDescriptor(PROBLEM_DEPTH_DESCRIPTOR);
setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" });
// Note: Remedy needs better OO design and therefore high effort // Note: Remedy needs better OO design and therefore high effort
setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 200); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 200);
setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false);
} }
public Object visit(ASTUserClass node, Object data) { public Object visit(ASTUserClass node, Object data) {
depth = 0; depth = 0;
depthLimit = getProperty(PROBLEM_DEPTH_DESCRIPTOR); depthLimit = getProperty(PROBLEM_DEPTH_DESCRIPTOR);
return super.visit(node, data); return super.visit(node, data);
} }
public Object visit(ASTIfBlockStatement node, Object data) { public Object visit(ASTIfBlockStatement node, Object data) {
depth++; depth++;
super.visit(node, data); super.visit(node, data);
if (depth == depthLimit) { if (depth == depthLimit) {
addViolation(data, node); addViolation(data, node);
} }
depth--; depth--;
return data; return data;
} }
} }

View File

@ -1,28 +1,28 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.rule.complexity; package net.sourceforge.pmd.lang.apex.rule.complexity;
import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
import net.sourceforge.pmd.lang.apex.ast.ASTParameter; import net.sourceforge.pmd.lang.apex.ast.ASTParameter;
import net.sourceforge.pmd.util.NumericConstants; import net.sourceforge.pmd.util.NumericConstants;
/** /**
* This rule detects an abnormally long parameter list. Note: This counts Nodes, * This rule detects an abnormally long parameter list. Note: This counts Nodes,
* and not necessarily parameters, so the numbers may not match up. (But * and not necessarily parameters, so the numbers may not match up. (But
* topcount and sigma should work.) * topcount and sigma should work.)
*/ */
public class ExcessiveParameterListRule extends ExcessiveNodeCountRule { public class ExcessiveParameterListRule extends ExcessiveNodeCountRule {
public ExcessiveParameterListRule() { public ExcessiveParameterListRule() {
super(ASTMethod.class); super(ASTMethod.class);
setProperty(MINIMUM_DESCRIPTOR, 4d); setProperty(MINIMUM_DESCRIPTOR, 4d);
setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" });
setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 50); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 50);
setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false);
} }
public Object visit(ASTParameter node, Object data) { public Object visit(ASTParameter node, Object data) {
return NumericConstants.ONE; return NumericConstants.ONE;
} }
} }

View File

@ -1,77 +1,77 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.rule.complexity; package net.sourceforge.pmd.lang.apex.rule.complexity;
import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.FINAL; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.FINAL;
import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.STATIC; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.STATIC;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.sourceforge.pmd.lang.apex.ast.ASTField; import net.sourceforge.pmd.lang.apex.ast.ASTField;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.properties.IntegerProperty; import net.sourceforge.pmd.lang.rule.properties.IntegerProperty;
import net.sourceforge.pmd.util.NumericConstants; import net.sourceforge.pmd.util.NumericConstants;
public class TooManyFieldsRule extends AbstractApexRule { public class TooManyFieldsRule extends AbstractApexRule {
private static final int DEFAULT_MAXFIELDS = 15; private static final int DEFAULT_MAXFIELDS = 15;
private Map<String, Integer> stats; private Map<String, Integer> stats;
private Map<String, ASTUserClass> nodes; private Map<String, ASTUserClass> nodes;
private static final IntegerProperty MAX_FIELDS_DESCRIPTOR = new IntegerProperty("maxfields", private static final IntegerProperty MAX_FIELDS_DESCRIPTOR = new IntegerProperty("maxfields",
"Max allowable fields", 1, 300, DEFAULT_MAXFIELDS, 1.0f); "Max allowable fields", 1, 300, DEFAULT_MAXFIELDS, 1.0f);
public TooManyFieldsRule() { public TooManyFieldsRule() {
definePropertyDescriptor(MAX_FIELDS_DESCRIPTOR); definePropertyDescriptor(MAX_FIELDS_DESCRIPTOR);
setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" }); setProperty(CODECLIMATE_CATEGORIES, new String[] { "Complexity" });
setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 200); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 200);
setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false);
} }
@Override @Override
public Object visit(ASTUserClass node, Object data) { public Object visit(ASTUserClass node, Object data) {
int maxFields = getProperty(MAX_FIELDS_DESCRIPTOR); int maxFields = getProperty(MAX_FIELDS_DESCRIPTOR);
stats = new HashMap<>(5); stats = new HashMap<>(5);
nodes = new HashMap<>(5); nodes = new HashMap<>(5);
List<ASTField> l = node.findDescendantsOfType(ASTField.class); List<ASTField> l = node.findDescendantsOfType(ASTField.class);
for (ASTField fd : l) { for (ASTField fd : l) {
if (fd.getNode().getModifierInfo().all(FINAL, STATIC)) { if (fd.getNode().getModifierInfo().all(FINAL, STATIC)) {
continue; continue;
} }
ASTUserClass clazz = fd.getFirstParentOfType(ASTUserClass.class); ASTUserClass clazz = fd.getFirstParentOfType(ASTUserClass.class);
if (clazz != null) { if (clazz != null) {
bumpCounterFor(clazz); bumpCounterFor(clazz);
} }
} }
for (Map.Entry<String, Integer> entry : stats.entrySet()) { for (Map.Entry<String, Integer> entry : stats.entrySet()) {
int val = entry.getValue(); int val = entry.getValue();
Node n = nodes.get(entry.getKey()); Node n = nodes.get(entry.getKey());
if (val > maxFields) { if (val > maxFields) {
addViolation(data, n); addViolation(data, n);
} }
} }
return data; return data;
} }
private void bumpCounterFor(ASTUserClass clazz) { private void bumpCounterFor(ASTUserClass clazz) {
String key = clazz.getImage(); String key = clazz.getImage();
if (!stats.containsKey(key)) { if (!stats.containsKey(key)) {
stats.put(key, NumericConstants.ZERO); stats.put(key, NumericConstants.ZERO);
nodes.put(key, clazz); nodes.put(key, clazz);
} }
Integer i = Integer.valueOf(stats.get(key) + 1); Integer i = Integer.valueOf(stats.get(key) + 1);
stats.put(key, i); stats.put(key, i);
} }
} }

View File

@ -1,33 +1,33 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.rule.style; package net.sourceforge.pmd.lang.apex.rule.style;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.ast.ASTUserInterface; import net.sourceforge.pmd.lang.apex.ast.ASTUserInterface;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
public class ClassNamingConventionsRule extends AbstractApexRule { public class ClassNamingConventionsRule extends AbstractApexRule {
public ClassNamingConventionsRule() { public ClassNamingConventionsRule() {
setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" }); setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" });
// Note: x10 as Apex has not automatic refactoring // Note: x10 as Apex has not automatic refactoring
setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 5); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 5);
setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false);
} }
public Object visit(ASTUserClass node, Object data) { public Object visit(ASTUserClass node, Object data) {
if (Character.isLowerCase(node.getImage().charAt(0))) { if (Character.isLowerCase(node.getImage().charAt(0))) {
addViolation(data, node); addViolation(data, node);
} }
return data; return data;
} }
public Object visit(ASTUserInterface node, Object data) { public Object visit(ASTUserInterface node, Object data) {
if (Character.isLowerCase(node.getImage().charAt(0))) { if (Character.isLowerCase(node.getImage().charAt(0))) {
addViolation(data, node); addViolation(data, node);
} }
return data; return data;
} }
} }

View File

@ -1,54 +1,54 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.rule.style; package net.sourceforge.pmd.lang.apex.rule.style;
import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.OVERRIDE; import static apex.jorje.semantic.symbol.type.ModifierTypeInfos.OVERRIDE;
import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
import net.sourceforge.pmd.lang.apex.ast.ASTProperty; import net.sourceforge.pmd.lang.apex.ast.ASTProperty;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
public class MethodNamingConventionsRule extends AbstractApexRule { public class MethodNamingConventionsRule extends AbstractApexRule {
public MethodNamingConventionsRule() { public MethodNamingConventionsRule() {
setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" }); setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" });
// Note: x10 as Apex has not automatic refactoring // Note: x10 as Apex has not automatic refactoring
setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 1); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 1);
setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false);
} }
public Object visit(ASTUserClass node, Object data) { public Object visit(ASTUserClass node, Object data) {
return super.visit(node, data); return super.visit(node, data);
} }
public Object visit(ASTMethod node, Object data) { public Object visit(ASTMethod node, Object data) {
if (isOverriddenMethod(node) || isPropertyAccessor(node) || isConstructor(node)) { if (isOverriddenMethod(node) || isPropertyAccessor(node) || isConstructor(node)) {
return data; return data;
} }
String methodName = node.getImage(); String methodName = node.getImage();
if (Character.isUpperCase(methodName.charAt(0))) { if (Character.isUpperCase(methodName.charAt(0))) {
addViolationWithMessage(data, node, "Method names should not start with capital letters"); addViolationWithMessage(data, node, "Method names should not start with capital letters");
} }
if (methodName.indexOf('_') >= 0) { if (methodName.indexOf('_') >= 0) {
addViolationWithMessage(data, node, "Method names should not contain underscores"); addViolationWithMessage(data, node, "Method names should not contain underscores");
} }
return data; return data;
} }
private boolean isOverriddenMethod(ASTMethod node) { private boolean isOverriddenMethod(ASTMethod node) {
return node.getNode().getModifiers().has(OVERRIDE); return node.getNode().getModifiers().has(OVERRIDE);
} }
private boolean isPropertyAccessor(ASTMethod node) { private boolean isPropertyAccessor(ASTMethod node) {
return (node.getParentsOfType(ASTProperty.class).size() > 0); return (node.getParentsOfType(ASTProperty.class).size() > 0);
} }
private boolean isConstructor(ASTMethod node) { private boolean isConstructor(ASTMethod node) {
return (node.getNode().getMethodInfo().isConstructor()); return (node.getNode().getMethodInfo().isConstructor());
} }
} }

View File

@ -1,38 +1,38 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex.rule.style; package net.sourceforge.pmd.lang.apex.rule.style;
import java.util.List; import java.util.List;
import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
public class MethodWithSameNameAsEnclosingClassRule extends AbstractApexRule { public class MethodWithSameNameAsEnclosingClassRule extends AbstractApexRule {
public MethodWithSameNameAsEnclosingClassRule() { public MethodWithSameNameAsEnclosingClassRule() {
setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" }); setProperty(CODECLIMATE_CATEGORIES, new String[] { "Style" });
// Note: x10 as Apex has not automatic refactoring // Note: x10 as Apex has not automatic refactoring
setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 50); setProperty(CODECLIMATE_REMEDIATION_MULTIPLIER, 50);
setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false); setProperty(CODECLIMATE_BLOCK_HIGHLIGHTING, false);
} }
@Override @Override
public Object visit(ASTUserClass node, Object data) { public Object visit(ASTUserClass node, Object data) {
String className = node.getImage(); String className = node.getImage();
List<ASTMethod> methods = node.findDescendantsOfType(ASTMethod.class); List<ASTMethod> methods = node.findDescendantsOfType(ASTMethod.class);
for (ASTMethod m : methods) { for (ASTMethod m : methods) {
String methodName = m.getImage(); String methodName = m.getImage();
if (!m.getNode().getMethodInfo().isConstructor() && methodName.equalsIgnoreCase(className)) { if (!m.getNode().getMethodInfo().isConstructor() && methodName.equalsIgnoreCase(className)) {
addViolation(data, m); addViolation(data, m);
} }
} }
return super.visit(node, data); return super.visit(node, data);
} }
} }

View File

@ -1,27 +1,27 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.apex; package net.sourceforge.pmd.lang.apex;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import org.junit.runners.Parameterized.Parameters; import org.junit.runners.Parameterized.Parameters;
import net.sourceforge.pmd.AbstractLanguageVersionTest; import net.sourceforge.pmd.AbstractLanguageVersionTest;
import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.LanguageVersion;
public class LanguageVersionTest extends AbstractLanguageVersionTest { public class LanguageVersionTest extends AbstractLanguageVersionTest {
public LanguageVersionTest(String name, String terseName, String version, LanguageVersion expected) { public LanguageVersionTest(String name, String terseName, String version, LanguageVersion expected) {
super(name, terseName, version, expected); super(name, terseName, version, expected);
} }
@Parameters @Parameters
public static Collection<?> data() { public static Collection<?> data() {
return Arrays.asList(new Object[][] { { ApexLanguageModule.NAME, ApexLanguageModule.TERSE_NAME, "35", return Arrays.asList(new Object[][] { { ApexLanguageModule.NAME, ApexLanguageModule.TERSE_NAME, "35",
LanguageRegistry.getLanguage("Apex").getVersion("35"), }, }); LanguageRegistry.getLanguage("Apex").getVersion("35"), }, });
} }
} }

View File

@ -1,22 +1,22 @@
/* This is a dummy JJTree used to generate the reusable aspects of JavaCC parsers. */ /* This is a dummy JJTree used to generate the reusable aspects of JavaCC parsers. */
options { options {
USER_CHAR_STREAM = true; USER_CHAR_STREAM = true;
} }
PARSER_BEGIN(DummyParser) PARSER_BEGIN(DummyParser)
package net.sourceforge.pmd.lang.ast.dummy; package net.sourceforge.pmd.lang.ast.dummy;
public class DummyParser public class DummyParser
{ {
} }
PARSER_END(DummyParser) PARSER_END(DummyParser)
TOKEN : TOKEN :
{ {
<DUMMY : "dummy"> <DUMMY : "dummy">
} }
ASTDummy Dummy() : ASTDummy Dummy() :
{} {}
{ {
<EOF> <EOF>
} }

View File

@ -1,97 +1,97 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd; package net.sourceforge.pmd;
/** /**
* These are the possible Rule priority values. * These are the possible Rule priority values.
* *
* For backward compatibility, priorities range in value from 1 to 5, with 5 * For backward compatibility, priorities range in value from 1 to 5, with 5
* being the lowest priority. This means the ordinal value of the Enum should be * being the lowest priority. This means the ordinal value of the Enum should be
* avoided in favor of {@link RulePriority#getPriority()} and * avoided in favor of {@link RulePriority#getPriority()} and
* {@link RulePriority#valueOf(int)} * {@link RulePriority#valueOf(int)}
* *
* @see <a href="http://pmd.sourceforge.net/pmd-5.1.2/rule-guidelines.html">How * @see <a href="http://pmd.sourceforge.net/pmd-5.1.2/rule-guidelines.html">How
* to define rules priority</a> * to define rules priority</a>
*/ */
public enum RulePriority { public enum RulePriority {
/** High: Change absolutely required. Behavior is critically broken/buggy */ /** High: Change absolutely required. Behavior is critically broken/buggy */
HIGH(1, "High"), HIGH(1, "High"),
/** /**
* Medium to high: Change highly recommended. Behavior is quite likely to be * Medium to high: Change highly recommended. Behavior is quite likely to be
* broken/buggy. * broken/buggy.
*/ */
MEDIUM_HIGH(2, "Medium High"), MEDIUM_HIGH(2, "Medium High"),
/** /**
* Medium: Change recommended. Behavior is confusing, perhaps buggy, and/or * Medium: Change recommended. Behavior is confusing, perhaps buggy, and/or
* against standards/best practices. * against standards/best practices.
*/ */
MEDIUM(3, "Medium"), MEDIUM(3, "Medium"),
/** /**
* Medium to low: Change optional. Behavior is not likely to be buggy, but * Medium to low: Change optional. Behavior is not likely to be buggy, but
* more just flies in the face of standards/style/good taste. * more just flies in the face of standards/style/good taste.
*/ */
MEDIUM_LOW(4, "Medium Low"), MEDIUM_LOW(4, "Medium Low"),
/** /**
* Low: Change highly optional. Nice to have, such as a consistent naming * Low: Change highly optional. Nice to have, such as a consistent naming
* policy for package/class/fields... * policy for package/class/fields...
*/ */
LOW(5, "Low"); LOW(5, "Low");
private final int priority; private final int priority;
private final String name; private final String name;
RulePriority(int priority, String name) { RulePriority(int priority, String name) {
this.priority = priority; this.priority = priority;
this.name = name; this.name = name;
} }
/** /**
* Get the priority value as a number. This is the value to be used in the * Get the priority value as a number. This is the value to be used in the
* externalized form of a priority (e.g. in RuleSet XML). * externalized form of a priority (e.g. in RuleSet XML).
* *
* @return The <code>int</code> value of the priority. * @return The <code>int</code> value of the priority.
*/ */
public int getPriority() { public int getPriority() {
return priority; return priority;
} }
/** /**
* Get the descriptive name of this priority. * Get the descriptive name of this priority.
* *
* @return The descriptive name. * @return The descriptive name.
*/ */
public String getName() { public String getName() {
return name; return name;
} }
/** /**
* Returns the descriptive name of the priority. * Returns the descriptive name of the priority.
* *
* @return descriptive name of the priority * @return descriptive name of the priority
* @see #getName() * @see #getName()
*/ */
@Override @Override
public String toString() { public String toString() {
return name; return name;
} }
/** /**
* Get the priority which corresponds to the given number as returned by * Get the priority which corresponds to the given number as returned by
* {@link RulePriority#getPriority()}. If the number is an invalid value, * {@link RulePriority#getPriority()}. If the number is an invalid value,
* then {@link RulePriority#LOW} will be returned. * then {@link RulePriority#LOW} will be returned.
* *
* @param priority * @param priority
* The numeric priority value. * The numeric priority value.
* @return The priority. * @return The priority.
*/ */
public static RulePriority valueOf(int priority) { public static RulePriority valueOf(int priority) {
try { try {
return RulePriority.values()[priority - 1]; return RulePriority.values()[priority - 1];
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
return LOW; return LOW;
} }
} }
} }

View File

@ -1,52 +1,52 @@
/** /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd; package net.sourceforge.pmd;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
/** /**
* This class represents a reference to RuleSet. * This class represents a reference to RuleSet.
*/ */
public class RuleSetReference { public class RuleSetReference {
private String ruleSetFileName; private String ruleSetFileName;
private boolean allRules; private boolean allRules;
private Set<String> excludes = new LinkedHashSet<>(0); private Set<String> excludes = new LinkedHashSet<>(0);
public RuleSetReference() { public RuleSetReference() {
} }
public RuleSetReference(String theFilename) { public RuleSetReference(String theFilename) {
ruleSetFileName = theFilename; ruleSetFileName = theFilename;
} }
public String getRuleSetFileName() { public String getRuleSetFileName() {
return ruleSetFileName; return ruleSetFileName;
} }
public void setRuleSetFileName(String ruleSetFileName) { public void setRuleSetFileName(String ruleSetFileName) {
this.ruleSetFileName = ruleSetFileName; this.ruleSetFileName = ruleSetFileName;
} }
public boolean isAllRules() { public boolean isAllRules() {
return allRules; return allRules;
} }
public void setAllRules(boolean allRules) { public void setAllRules(boolean allRules) {
this.allRules = allRules; this.allRules = allRules;
} }
public Set<String> getExcludes() { public Set<String> getExcludes() {
return excludes; return excludes;
} }
public void setExcludes(Set<String> excludes) { public void setExcludes(Set<String> excludes) {
this.excludes = excludes; this.excludes = excludes;
} }
public void addExclude(String name) { public void addExclude(String name) {
this.excludes.add(name); this.excludes.add(name);
} }
} }

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More