5366 Commits

Author SHA1 Message Date
Ryan Gustafson
5325eaab2f Add support for adding Rules to a RuleSet by reference. Useful for IDE plugins, which intend to allow defining custom RuleSets using existing Rules without the current copy semantics. Essentially, this lets us more easily do programmatically what we can already do in a hand-written XML.
For this to work, a Rule/RuleSet being added by Reference must have a file name associated with it. This information will be associated with the RuleSet when created by the RuleSetFactory using the APIs which provide file names/resources.  If a raw InputStream form is used, then the file name will need to be manually set.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5777 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-15 19:04:11 +00:00
Romain Pelisse
08f5509930 Fix for bug 1882457
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5776 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-15 19:03:30 +00:00
Romain Pelisse
37a0f03f2e Adding a test case to assert proper behavior when user does not provide configuration for showMethodsComplexity and showClassesComplexity. Default is resolved as "true". Test doesn't fail, it seems ok.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5775 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-14 13:03:43 +00:00
Romain Pelisse
6e97f66bf9 Small upgrade to CyclomaticComplexity. By default, the rule add two kind of violation (method violation, but also a class average complexity). Some user find that troublesome and it maybe messy if an aggregated report. So i had a simple configuration to the rule. I also had a couple of unit test to ensure proper behavior of this modification.
Code cleaning, switching inheritance to AbstractJavaRule.

Adding proper documentation to the new rule's properties.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5774 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-14 09:08:47 +00:00
Romain Pelisse
dd4b2b9112 Small upgrade to CyclomaticComplexity. By default, the rule add two kind of violation (method violation, but also a class average complexity). Some user find that troublesome and it maybe messy if an aggregated report. So i had a simple configuration to the rule. I also had a couple of unit test to ensure proper behavior of this modification.
Code cleaning, switching inheritance to AbstractJavaRule.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5773 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-14 09:06:49 +00:00
Romain Pelisse
17546aaa70 code cleaning (javadoc)
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5772 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-14 08:35:44 +00:00
Romain Pelisse
d78d546f6a Code cleaning, switching inheritance from deprecated AbstractRule to AbstractJavaRule.
This did not broke any test, so it seems fine.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5771 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-14 08:34:15 +00:00
Ryan Gustafson
02510413f1 Use looser regex to cleanup the XML Declaration for DTD tests, to accommodate JDK6 use of 'standalone'.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5770 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-13 05:14:12 +00:00
Xavier Le Vourch
9d5b78a6b1 Designer: selecting an AST in the result list will highlist it in the code window too
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5769 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-13 04:29:04 +00:00
Ryan Gustafson
d456a8074f Comment out some debug System.out.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5768 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-13 04:04:23 +00:00
Ryan Gustafson
66e2c18261 Refactor MockRule to be part of PMD core, as an actual Rule implementation which does nothing is useful beyond just unit testing (e.g. in IDE plugin development).
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5767 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-13 03:57:04 +00:00
Xavier Le Vourch
02eb9575e0 bug fix: invalide test case for TooFewBranchesForASwitchStatement
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5766 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-13 03:29:33 +00:00
Xavier Le Vourch
6049be38fa bug fix: incorrect XPath expression for TooFewBranchesForASwitchStatement
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5765 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-13 03:29:16 +00:00
Ryan Gustafson
f46b8fc0ba RuleSetWriter class can be used to Serialize a RuleSet to XML in a standard fashion. Recommend PMD IDE plugins standardize their behavior.
The essence of this change is to add the RuleReference and RuleSetReference classes, which contain the details that were previously missing from the runtime representation which are available in the XML, specifically the details about usage of Rules by reference.  This now means that XML <-> runtime RuleSet are interchangeable, a modification in one can be reflected in the other.  PMD IDE plugins which support Rule editing can now use the core PMD classes and standard XML serialization, instead of implementing custom value 
objects and serialization mechanisms.

The RuleReference class is essentially a wrapping around an existing Rule instance.  It is the RuleReference which is directly contained in the RuleSet now, instead of the original Rule instance.  Any code which uses instanceof checks on Rule instances will have problem when encountering a RuleReference.  Thankfully this is a rare occurrence, only the RuleChain code seemed to have to be tweaked to deal with this.  Even so, I wouldn't be surprised if something turns up that needs to be addressed.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5764 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-12 22:38:44 +00:00
Xavier Le Vourch
60b76a7f10 spelling
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5763 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-12 18:44:33 +00:00
Romain Pelisse
0a99ac7e21 Small upgrade to the designer : I moved SymbolTableResultPanel below the ASTPanel. I really suck with Swing so I wasn't able to give it the proper ratio ( 7/10 of the panel for ASTPanel, 3/10 seems pretty fine with me).
I also did some code cleaning.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5762 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-12 18:40:39 +00:00
Xavier Le Vourch
54c3441c29 code cleanup: pmdOnPmd warnings
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5761 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-12 18:27:55 +00:00
Romain Pelisse
15ff2356bd Adding a "help to newbie" feature for the designer. I enhanced tooltip to provide access data (such as Abstract, Native...). The idea is that when i start designing pmd rules with the designer it was not always clear (for me) on which kind of node i'll be able to find such a data. So now, any special keyword on a AccessNode will appear in the tooltip.
I already implemented this 6 month ago but i didn't have the commit it. Since the designer class has been revised,my modifications, still on the patch tracker, became obsolete. 


 


git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5760 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-12 15:50:22 +00:00
Romain Pelisse
b1fa90e85c Removing HttpFilterCounterRule still not ready ...
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5759 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-12 09:06:55 +00:00
Xavier Le Vourch
a324c170c1 PMD Rule Designer shows position info in tooltip for AST nodes and highlights matching code for selected AST node in code window.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5758 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-12 02:30:15 +00:00
Romain Pelisse
e18e69e122 Bug fix : [ 1888967 ] False +: EmptyMethodInAbstractClassShouldBeAbstract
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5757 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-11 17:50:35 +00:00
Romain Pelisse
d143732355 Fixing out of dated XPath Query, bug [1874313] Documentation bugs. Thanks to Dave Cronin for the report!
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5756 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-11 16:44:11 +00:00
Ryan Gustafson
4bb7d51339 Standardize usage of FilenameFilter to use Filter APIs. Add File extension and Directory searching to Filter APIs.
This is an incremental cleanup.  The real cleanup is the unify all these Language specific concepts across the entire PMD code base.  Specifically, the CPD Language stuff, SourceType, SourceTypeHandler, TargetJDK, Parsers, AST nodes, and anything else I missed.  That change will wait until we're ready to do a major PMD internal refactoring.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5755 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-11 12:07:25 +00:00
Ryan Gustafson
caae2e154e Improvements to the Filter infrastructure.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5754 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-11 11:05:54 +00:00
Ryan Gustafson
402645df5b Refactor cpd.FileFinder to pmd.util.FileFinder. Old class is now @deprecated (and unused within PMD itself).
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5753 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-11 09:05:02 +00:00
Ryan Gustafson
f923ddd04a CPD Ant task will report to System.out when 'outputFile' not given.
Added 'cpdOnPmd' target to PMD build.xml.  Yeah! More dogfood!

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5752 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-11 08:59:04 +00:00
Ryan Gustafson
ec6f6b0e91 CPD Ant task will report to System.out when 'outputFile' not given.
Added 'cpdOnPmd' target to PMD build.xml.  Yeah! More dogfood!

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5751 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-11 08:41:09 +00:00
Ryan Gustafson
00bb128289 Oops, accidentally removed a JScrollPane for the Source Code window.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5750 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-11 08:06:37 +00:00
Ryan Gustafson
7b5afa03ac PMD Rule Designer can now shows Symbol Table contents for the selected AST node.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5749 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-11 07:49:27 +00:00
Ryan Gustafson
b31f691012 Rules can now be written which produce violations based upon aggregate file processing (i.e. cross/multiple file violations).
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5748 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-11 01:24:10 +00:00
Romain Pelisse
7f9f3f5c9d Addind two new rules (again out of the Lint4J rules), with proper unit testing (and both 42.xml and etc/changelog updated).
- AbstractClassWithoutAnyMethod
	- TooFewBranchesForASwitchStatement
	
Also, i disabled rule and test about the HttpFilterCounter rule, that is still buggy...

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5747 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-09 22:42:07 +00:00
Romain Pelisse
63e05cdcf3 As usual, i forgot this one when i commited the new rule AvoidStringBuffer as field...
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5746 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-09 21:13:27 +00:00
Romain Pelisse
9cd5044506 Refactoring to match rule naming rather than implementing class, which is Generic.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5745 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-09 17:14:18 +00:00
Romain Pelisse
4927110084 Externalising generic methods, about regex, i wrote and used for both GenericClassCounter and GenericLiteralChecker. I create a package just for it, maybe it's overkill, maybe we should rename it helper ? I don't know really know, so fell free to refactor this if you don't feel this deserves a package.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5744 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-09 17:12:02 +00:00
Romain Pelisse
b77668fa16 Swith inheritance to AbstractJavaRule, as AbstractRule is deprecated.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5743 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-09 16:43:13 +00:00
Romain Pelisse
f9de48c1ce Adding a new rule AvoidStringBufferField.xml inspired by Lint4J one (http://www.jutils.com/checks/performance.html), with appropriate test case, and entry in changelog.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5742 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-09 16:37:40 +00:00
Romain Pelisse
59a0af1b9f Small upgrade on the documentation...
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5741 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-09 11:52:48 +00:00
Romain Pelisse
538769360f Adding documentation for Ryan's new feature (not DCD, the "violations based upon aggregate file processing (i.e. cross/multiple file violations).").
I've begin to implements such a rule (well, more of a generic rule). I'll try to finish tonight. I also added a test case.

Thanks Ryan for this, somehow small, but quite usefull upgrade ;) ! 

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5740 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-09 11:45:18 +00:00
Ryan Gustafson
b3d34c346c Rules can now be written which produce violations based upon aggregate file processing (i.e. cross/multiple file violations).
Added Rule.start() and Rule.end() for pre/post processing hooks.  Added shared attributes to RuleContext for storage of shared state across all Rule.apply() invocations.  Essentially a rule could on (1) Rule.start() does any necessary setup on RuleContext attributes, (2) Rule.apply() accumulates results in RuleContext attributes (must be thread-safe!), (3) Rule.end() gets/removes RuleContext attributes to produce any necessary violations.

Inane example:

package net.sourceforge.pmd.rules;

import java.util.concurrent.atomic.AtomicLong;

import net.sourceforge.pmd.AbstractJavaRule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.ast.ASTExpression;

public class CountRule extends AbstractJavaRule {

	private static final String COUNT = "count";

	@Override
	public void start(RuleContext ctx) {
		ctx.setAttribute(COUNT, new AtomicLong());
		super.start(ctx);
	}

	@Override
	public Object visit(ASTExpression node, Object data) {
		// How many Expression nodes are there in all files parsed!  I must know!
		RuleContext ctx = (RuleContext)data;
		AtomicLong total = (AtomicLong)ctx.getAttribute(COUNT);
		total.incrementAndGet();
		return super.visit(node, data);
	}

	@Override
	public void end(RuleContext ctx) {
		AtomicLong total = (AtomicLong)ctx.getAttribute(COUNT);
		addViolation(ctx, null, new Object[] { total });
		ctx.removeAttribute(COUNT);
		super.start(ctx);
	}
}


git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5739 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-09 05:39:27 +00:00
Ryan Gustafson
2294864833 Initial version of Dead Code Detector. Provides a foundation data structures for the problem. Boatload of work yet to be done. See JavaDoc on DCD.java and UsageGraph.java for details. See TODOs in DCD.java for ideas of what needs to be done yet.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5738 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-07 10:01:31 +00:00
Ryan Gustafson
b178c29a24 Minor tweak to reduce attempts to resolve types for non-existent classes. Minor code reformat.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5737 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-05 22:38:42 +00:00
Ryan Gustafson
ed4ce5b28f Add utility Filter API for filtering arbitrary objects. Support for AND/OR/NOT logical operations, as well as basic String regex matching. FilterBuilder contains convenience methods for building a Filter.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5736 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-05 21:16:24 +00:00
Ryan Gustafson
cb4ac74e59 JavaDoc fix.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5735 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-05 21:12:14 +00:00
Ryan Gustafson
9f86c8b174 Refactored Rule base classes around Rule interface instead of around AST Visitor interfaces.
Long term goal is to support additional languages beyond Java.  Organized like so:

   pmd.AbstractRule          // Core Rule implementation
   pmd.XPathRule             // Core XPath Rule implementation
   pmd.java.AbstractJavaRule // Java specific Rule implementation
   pmd.jsp.AbstractJspRule   // JSP specific Rule implementation
   pmd.xxx.AbstractXxxRule   // Language XXX specific Rule implementation
   ...

This is a start, there's a much larger reorganizing effort to get things in sync.  Additional work is needed on generalizing XPathRule.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5734 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-05 05:11:17 +00:00
Ryan Gustafson
a6ac5b1002 PMD on PMD
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5733 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-05 04:34:35 +00:00
Ryan Gustafson
588117d0bd Reorder methods for clarity. Add JavaDoc. Add // FUTURE comments. Deprecated include()/setInclude(boolean).
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5732 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-05 00:21:28 +00:00
Ryan Gustafson
a06e24ce14 New elements under <ruleset>: <exclude-pattern> to match files exclude from processing, with <include-pattern> to override.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5731 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-04 11:23:07 +00:00
Romain Pelisse
1857abbcab Bug fix for [1843273] False - on SimplifyBooleanReturns
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5730 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-04 09:09:35 +00:00
Romain Pelisse
df84a10760 Adding test case for bug [ 1843273 ] False - on SimplifyBooleanReturns
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5729 51baf565-9d33-0410-a72c-fc3788e3496d
2008-02-01 16:19:23 +00:00
Romain Pelisse
ede7411582 Removing erronous commit.
Sorry.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5728 51baf565-9d33-0410-a72c-fc3788e3496d
2008-01-26 12:12:54 +00:00