diff --git a/pmd-jedit/PMDPlugin/LICENSE.txt b/pmd-jedit/PMDPlugin/LICENSE.txt deleted file mode 100644 index 801cb60717..0000000000 --- a/pmd-jedit/PMDPlugin/LICENSE.txt +++ /dev/null @@ -1,2 +0,0 @@ -http://cougaar.org/docman/view.php/17/58/license.html - diff --git a/pmd-jedit/PMDPlugin/PMDPlugin.props b/pmd-jedit/PMDPlugin/PMDPlugin.props deleted file mode 100644 index 2e587fdf66..0000000000 --- a/pmd-jedit/PMDPlugin/PMDPlugin.props +++ /dev/null @@ -1,119 +0,0 @@ -# -# Plugin properties -# -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.name=PMDPlugin -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.author=Jiger Patel, Tom Copeland, Alan Ezust, Dale Anson -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.version=5.0.1 -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.docs=doc/jedit.html -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.0=jdk 1.5 -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.1=jedit 04.03.99.00 -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.2=plugin errorlist.ErrorListPlugin 2.0 -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.3=plugin CommonControlsPlugin 1.2 -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.3=plugin rhino.RhinoPlugin 1.7R4 -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-5.1.0.jar jaxen-1.1.1.jar asm-3.2.jar -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.description=The PMD plugin is a Java source code analysis tool. - - -# -# Menu properties -# - -# set activate on startup so that PMD can check automatically on save. If the -# user unchecks the option to run on save, this setting will change to 'defer'. -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.activate=startup - -# default is to run on save -pmd.runPMDOnSave=true - -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.menu.label=$PMD - -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.menu=pmd-check-current-buffer pmd-check-all-open-buffers pmd-check-directory pmd-clear-errorlist pmd-run-designer %pmd-cpd -pmd-cpd=cpd-currentfile cpd-dir -browser-pmd-cpd=cpd-currentfile cpd-dir cpd-dir-recursively - -#Dockables and Menu Labels -pmd-check-current-buffer.label=Check current buffer -pmd-check-all-open-buffers.label=Check all open buffers -pmd-check-directory.label=Check all files in directory -pmd-check-directory-recursively.label=Check all files in directory recursively -pmd-clear-errorlist.label=Clear ErrorList -pmd-run-designer.label=Run Rule Designer -pmd-cpd.label=Detect Duplicate Code -browser-pmd-cpd.label=Detect Duplicate Code -cpd-currentfile.label=In Current File -cpd-dir.label=In Directory -cpd-dir-recursively.label=In Directory Recursively -pmd-check-file.label=Check selected file(s) -cpd-viewer.label=Copy/Paste Detector - - -# -# Option pane properties -# -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.option-group=pmd.general pmd.rules pmd.cpd.general - -#plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.option-pane=pmd -options.pmd.general.label=PMD Settings -options.pmd.general.code=new net.sourceforge.pmd.jedit.PMDGeneralOptionPane() -options.pmd.rules.label=PMD Rules -options.pmd.rules.code=new net.sourceforge.pmd.jedit.PMDRulesOptionPane() -options.pmd.printRule=false -options.pmd.cpd.general.label=CPD Settings -options.pmd.cpd.general.code=new net.sourceforge.pmd.jedit.CPDOptionPane() - -#Dockables properties. -cpd-viewer.title=Copy/Paste Detector - -#FS Browser properties - -plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.browser-menu=pmd-check-file pmd-check-directory pmd-check-directory-recursively %browser-pmd-cpd - -#pmd properties -pmd.renderer=None -pmd.showprogress=true -pmd.progressbar.foreground=#000000 -pmd.progressbar.background=#FFC800 - - - -# various strings -net.sf.pmd.CPD,_Select_File_Type=CPD, Select File Type -net.sf.pmd.CPD_does_not_yet_support_this_file_type>_=CPD does not yet support this file type: -net.sf.pmd.Cannot_run_CPD_on_Invalid_directory/files.=Cannot run CPD on Invalid directory/files. -net.sf.pmd.Clear_ErrorList_on_Save=Clear ErrorList on Save -net.sf.pmd.Copy/Paste_Detector=Copy/Paste Detector -net.sf.pmd.Copy/Paste_detection_can_not_be_performed_on_this_file\nbecause_the_mode_can_not_be_determined.=Copy/Paste detection can not be performed on this file\nbecause the mode can not be determined. -net.sf.pmd.Description=Description -net.sf.pmd.Error_Loading_Custom_Ruleset=Error Loading Custom Ruleset -net.sf.pmd.Error_Loading_Rules=Error Loading Rules -net.sf.pmd.Error_loading_rules._Check_any_custom_rulesets_for_errors.=Error loading rules. Check any custom rulesets for errors. -net.sf.pmd.Error_while_processing_=Error while processing -net.sf.pmd.Example=Example -net.sf.pmd.Exclusions=Exclusions -net.sf.pmd.Export_Output_as_=Export Output as: -net.sf.pmd.Ignore_Literals_&_identifiers_when_detecting_Duplicate_Code=Ignore Literals & identifiers when detecting Duplicate Code -net.sf.pmb.Inclustions=Inclusions -net.sf.pmd.Invalid_Renderer=Invalid Renderer -net.sf.pmd.Minimum_Tile_Size>=Minimum Tile Size: -net.sf.pmd.Minimum_Tile_size_>=Minimum Tile size : -net.sf.pmd.No_duplicates_found.=No duplicates found. -net.sf.pmd.No_problems_found=No problems found -net.sf.pmd.One_Directory_has_to_be_selected_in_which_to_detect_duplicate_code.=One Directory has to be selected in which to detect duplicate code. -net.sf.pmd.One_file_must_be_selected=One file must be selected -net.sf.pmd.PMD_Check_in_Progress=PMD Check in Progress -net.sf.pmd.PMD_General_Options=PMD General Options -net.sf.pmd.Please_see_http>//pmd.sf.net/_for_more_information=Please see http://pmd.sf.net/ for more information -net.sf.pmd.Print_Rulename_in_ErrorList=Print Rulename in ErrorList -net.sf.pmd.Recursive=Recursive -net.sf.pmd.Rules=Rules -net.sf.pmd.Run_PMD_on_Save=Run PMD on Save -net.sf.pmd.Select_default_rules=Select default rules -net.sf.pmd.Select_type_of_files_to_check>=Select type of files to check: -net.sf.pmd.Selected_file_cannot_be_a_Directory.=Selected file cannot be a Directory. -net.sf.pmd.Selected_file_must_be_a_Directory.=Selected file must be a Directory. -net.sf.pmd.Selection_must_be_a_directory=Selection must be a directory -net.sf.pmd.Selection_not_a_directory.=Selection not a directory. -net.sf.pmd.Show_PMD_Progress_Bar=Show PMD Progress Bar -net.sf.pmd.There_was_an_error_loading_one_or_more_custom_rulesets,_so_no_custom_rulesets_were_loaded=There was an error loading one or more custom rulesets, so no custom rulesets were loaded -net.sf.pmd.Unable_to_find_rulesets,_halting_PMD=Unable to find rulesets, halting PMD - diff --git a/pmd-jedit/PMDPlugin/actions.xml b/pmd-jedit/PMDPlugin/actions.xml deleted file mode 100644 index 83db621008..0000000000 --- a/pmd-jedit/PMDPlugin/actions.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.check(buffer, view); - - - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.checkAllOpenBuffers(view); - - - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view); - - - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.clearErrorList(); - - - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.runDesigner(); - - - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdCurrentFile(view); - - - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view); - - - diff --git a/pmd-jedit/PMDPlugin/browser.actions.xml b/pmd-jedit/PMDPlugin/browser.actions.xml deleted file mode 100644 index 5a5f1e9ddb..0000000000 --- a/pmd-jedit/PMDPlugin/browser.actions.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.checkFile(view,browser); - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view, browser,false); - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view, browser,true); - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdCurrentFile(view, browser); - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view,browser, false); - - - - net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view,browser, true); - - - diff --git a/pmd-jedit/PMDPlugin/build.xml b/pmd-jedit/PMDPlugin/build.xml deleted file mode 100644 index 7b2bba8647..0000000000 --- a/pmd-jedit/PMDPlugin/build.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Reloading ${install.dir}/${ant.project.name}.jar - - - - - diff --git a/pmd-jedit/PMDPlugin/default_rules.props b/pmd-jedit/PMDPlugin/default_rules.props deleted file mode 100644 index d8a88ecba3..0000000000 --- a/pmd-jedit/PMDPlugin/default_rules.props +++ /dev/null @@ -1,238 +0,0 @@ -# select some default rules to help new users get started. The selected rules -# are those suggested by PMD best practices -- unused code, basic rules, some -# design rules, a few controversial rules, and imports rules. -options.pmd.rules.AbstractClassWithoutAbstractMethod=false -options.pmd.rules.AbstractClassWithoutAnyMethod=false -options.pmd.rules.AbstractNaming=false -options.pmd.rules.AccessorClassGeneration=false -options.pmd.rules.AddEmptyString=false -options.pmd.rules.AppendCharacterWithChar=true -options.pmd.rules.ArrayIsStoredDirectly=true -options.pmd.rules.AssignmentInOperand=false -options.pmd.rules.AssignmentToNonFinalStatic=false -options.pmd.rules.AtLeastOneConstructor=false -options.pmd.rules.AvoidAccessibilityAlteration=false -options.pmd.rules.AvoidArrayLoops=false -options.pmd.rules.AvoidAssertAsIdentifier=false -options.pmd.rules.AvoidCallingFinalize=false -options.pmd.rules.AvoidCatchingNPE=true -options.pmd.rules.AvoidCatchingThrowable=true -options.pmd.rules.AvoidConstantsInterface=false -options.pmd.rules.AvoidDecimalLiteralsInBigDecimalConstructor=true -options.pmd.rules.AvoidDeeplyNestedIfStmts=false -options.pmd.rules.AvoidDollarSigns=false -options.pmd.rules.AvoidDuplicateLiterals=true -options.pmd.rules.AvoidEnumAsIdentifier=false -options.pmd.rules.AvoidFieldNameMatchingMethodName=false -options.pmd.rules.AvoidFieldNameMatchingTypeName=false -options.pmd.rules.AvoidFinalLocalVariable=false -options.pmd.rules.AvoidInstanceofChecksInCatchClause=false -options.pmd.rules.AvoidInstantiatingObjectsInLoops=false -options.pmd.rules.AvoidMultipleUnaryOperators=true -options.pmd.rules.AvoidPrintStackTrace=false -options.pmd.rules.AvoidProtectedFieldInFinalClass=false -options.pmd.rules.AvoidReassigningParameters=false -options.pmd.rules.AvoidRethrowingException=true -options.pmd.rules.AvoidStringBufferField=true -options.pmd.rules.AvoidSynchronizedAtMethodLevel=false -options.pmd.rules.AvoidThreadGroup=true -options.pmd.rules.AvoidThrowingNewInstanceOfSameException=true -options.pmd.rules.AvoidThrowingNullPointerException=true -options.pmd.rules.AvoidThrowingRawExceptionTypes=true -options.pmd.rules.AvoidUsingHardCodedIP=true -options.pmd.rules.AvoidUsingNativeCode=false -options.pmd.rules.AvoidUsingOctalValues=true -options.pmd.rules.AvoidUsingShortType=false -options.pmd.rules.AvoidUsingVolatile=false -options.pmd.rules.BadComparison=false -options.pmd.rules.BeanMembersShouldSerialize=false -options.pmd.rules.BigIntegerInstantiation=true -options.pmd.rules.BooleanGetMethodName=false -options.pmd.rules.BooleanInstantiation=true -options.pmd.rules.BooleanInversion=false -options.pmd.rules.BrokenNullCheck=true -options.pmd.rules.ByteInstantiation=false -options.pmd.rules.CallSuperFirst=false -options.pmd.rules.CallSuperInConstructor=false -options.pmd.rules.CallSuperLast=false -options.pmd.rules.CheckResultSet=true -options.pmd.rules.ClassCastExceptionWithToArray=true -options.pmd.rules.ClassNamingConventions=false -options.pmd.rules.ClassWithOnlyPrivateConstructorsShouldBeFinal=false -options.pmd.rules.CloneMethodMustImplementCloneable=false -options.pmd.rules.CloneThrowsCloneNotSupportedException=false -options.pmd.rules.CloseResource=false -options.pmd.rules.CollapsibleIfStatements=true -options.pmd.rules.CompareObjectsWithEquals=false -options.pmd.rules.ConfusingTernary=false -options.pmd.rules.ConsecutiveLiteralAppends=true -options.pmd.rules.ConstructorCallsOverridableMethod=false -options.pmd.rules.CouplingBetweenObjects=false -options.pmd.rules.CyclomaticComplexity=false -options.pmd.rules.DataflowAnomalyAnalysis=false -options.pmd.rules.DefaultLabelNotLastInSwitchStmt=false -options.pmd.rules.DefaultPackage=false -options.pmd.rules.DoNotCallGarbageCollectionExplicitly=false -options.pmd.rules.DoNotCallSystemExit=false -options.pmd.rules.DoNotExtendJavaLangError=true -options.pmd.rules.DoNotThrowExceptionInFinally=true -options.pmd.rules.DoNotUseThreads=false -options.pmd.rules.DontImportJavaLang=true -options.pmd.rules.DontImportSun=false -options.pmd.rules.DoubleCheckedLocking=true -options.pmd.rules.DuplicateImports=true -options.pmd.rules.EmptyCatchBlock=true -options.pmd.rules.EmptyFinalizer=false -options.pmd.rules.EmptyFinallyBlock=true -options.pmd.rules.EmptyIfStmt=true -options.pmd.rules.EmptyInitializer=true -options.pmd.rules.EmptyMethodInAbstractClassShouldBeAbstract=false -options.pmd.rules.EmptyStatementNotInLoop=true -options.pmd.rules.EmptyStaticInitializer=true -options.pmd.rules.EmptySwitchStatements=true -options.pmd.rules.EmptySynchronizedBlock=true -options.pmd.rules.EmptyTryBlock=true -options.pmd.rules.EmptyWhileStmt=true -options.pmd.rules.EqualsNull=false -options.pmd.rules.ExceptionAsFlowControl=true -options.pmd.rules.ExcessiveClassLength=false -options.pmd.rules.ExcessiveImports=false -options.pmd.rules.ExcessiveMethodLength=false -options.pmd.rules.ExcessiveParameterList=false -options.pmd.rules.ExcessivePublicCount=false -options.pmd.rules.FinalFieldCouldBeStatic=false -options.pmd.rules.FinalizeDoesNotCallSuperFinalize=false -options.pmd.rules.FinalizeOnlyCallsSuperFinalize=false -options.pmd.rules.FinalizeOverloaded=false -options.pmd.rules.FinalizeShouldBeProtected=false -options.pmd.rules.ForLoopShouldBeWhileLoop=true -options.pmd.rules.ForLoopsMustUseBraces=false -options.pmd.rules.IdempotentOperations=false -options.pmd.rules.IfElseStmtsMustUseBraces=false -options.pmd.rules.IfStmtsMustUseBraces=false -options.pmd.rules.ImmutableField=false -options.pmd.rules.ImportFromSamePackage=true -options.pmd.rules.InefficientEmptyStringCheck=true -options.pmd.rules.InefficientStringBuffering=true -options.pmd.rules.InstantiationToGetClass=false -options.pmd.rules.InsufficientStringBufferDeclaration=true -options.pmd.rules.IntegerInstantiation=false -options.pmd.rules.JUnit4SuitesShouldUseSuiteAnnotation=false -options.pmd.rules.JUnit4TestShouldUseAfterAnnotation=false -options.pmd.rules.JUnit4TestShouldUseBeforeAnnotation=false -options.pmd.rules.JUnit4TestShouldUseTestAnnotation=false -options.pmd.rules.JUnitAssertionsShouldIncludeMessage=false -options.pmd.rules.JUnitSpelling=false -options.pmd.rules.JUnitStaticSuite=false -options.pmd.rules.JUnitTestsShouldIncludeAssert=false -options.pmd.rules.JUnitUseExpected=false -options.pmd.rules.JumbledIncrementer=true -options.pmd.rules.LocalHomeNamingConvention=false -options.pmd.rules.LocalInterfaceSessionNamingConvention=false -options.pmd.rules.LocalVariableCouldBeFinal=false -options.pmd.rules.LoggerIsNotStaticFinal=false -options.pmd.rules.LongInstantiation=false -options.pmd.rules.LongVariable=false -options.pmd.rules.LooseCoupling=false -options.pmd.rules.MDBAndSessionBeanNamingConvention=false -options.pmd.rules.MethodArgumentCouldBeFinal=false -options.pmd.rules.MethodNamingConventions=false -options.pmd.rules.MethodReturnsInternalArray=true -options.pmd.rules.MethodWithSameNameAsEnclosingClass=false -options.pmd.rules.MisleadingVariableName=false -options.pmd.rules.MisplacedNullCheck=true -options.pmd.rules.MissingBreakInSwitch=false -options.pmd.rules.MissingSerialVersionUID=false -options.pmd.rules.MissingStaticMethodInNonInstantiatableClass=false -options.pmd.rules.MoreThanOneLogger=false -options.pmd.rules.NPathComplexity=false -options.pmd.rules.NcssConstructorCount=false -options.pmd.rules.NcssMethodCount=false -options.pmd.rules.NcssTypeCount=false -options.pmd.rules.NoPackage=false -options.pmd.rules.NonCaseLabelInSwitchStatement=false -options.pmd.rules.NonStaticInitializer=false -options.pmd.rules.NonThreadSafeSingleton=false -options.pmd.rules.NullAssignment=false -options.pmd.rules.OnlyOneReturn=false -options.pmd.rules.OptimizableToArrayCall=false -options.pmd.rules.OverrideBothEqualsAndHashcode=true -options.pmd.rules.PackageCase=false -options.pmd.rules.PositionLiteralsFirstInComparisons=false -options.pmd.rules.PreserveStackTrace=false -options.pmd.rules.ProperCloneImplementation=false -options.pmd.rules.ProperLogger=false -options.pmd.rules.RemoteInterfaceNamingConvention=false -options.pmd.rules.RemoteSessionInterfaceNamingConvention=false -options.pmd.rules.ReplaceEnumerationWithIterator=false -options.pmd.rules.ReplaceHashtableWithMap=false -options.pmd.rules.ReplaceVectorWithList=false -options.pmd.rules.ReturnEmptyArrayRatherThanNull=false -options.pmd.rules.ReturnFromFinallyBlock=true -options.pmd.rules.ShortInstantiation=false -options.pmd.rules.ShortMethodName=false -options.pmd.rules.ShortVariable=false -options.pmd.rules.SignatureDeclareThrowsException=true -options.pmd.rules.SimpleDateFormatNeedsLocale=false -options.pmd.rules.SimplifyBooleanAssertion=false -options.pmd.rules.SimplifyBooleanExpressions=false -options.pmd.rules.SimplifyBooleanReturns=false -options.pmd.rules.SimplifyConditional=false -options.pmd.rules.SimplifyStartsWith=false -options.pmd.rules.SingularField=true -options.pmd.rules.StaticEJBFieldShouldBeFinal=false -options.pmd.rules.StringBufferInstantiationWithChar=true -options.pmd.rules.StringInstantiation=true -options.pmd.rules.StringToString=true -options.pmd.rules.SuspiciousConstantFieldName=false -options.pmd.rules.SuspiciousEqualsMethodName=false -options.pmd.rules.SuspiciousHashcodeMethodName=false -options.pmd.rules.SuspiciousOctalEscape=false -options.pmd.rules.SwitchDensity=false -options.pmd.rules.SwitchStmtsShouldHaveDefault=false -options.pmd.rules.SystemPrintln=false -options.pmd.rules.TestClassWithoutTestCases=false -options.pmd.rules.TooFewBranchesForASwitchStatement=false -options.pmd.rules.TooManyFields=false -options.pmd.rules.TooManyMethods=false -options.pmd.rules.TooManyStaticImports=true -options.pmd.rules.UncommentedEmptyConstructor=false -options.pmd.rules.UncommentedEmptyMethod=false -options.pmd.rules.UnconditionalIfStatement=true -options.pmd.rules.UnnecessaryBooleanAssertion=false -options.pmd.rules.UnnecessaryCaseChange=true -options.pmd.rules.UnnecessaryConstructor=false -options.pmd.rules.UnnecessaryConversionTemporary=true -options.pmd.rules.UnnecessaryFinalModifier=true -options.pmd.rules.UnnecessaryLocalBeforeReturn=false -options.pmd.rules.UnnecessaryParentheses=false -options.pmd.rules.UnnecessaryReturn=true -options.pmd.rules.UnnecessaryWrapperObjectCreation=false -options.pmd.rules.UnsynchronizedStaticDateFormatter=false -options.pmd.rules.UnusedFormalParameter=true -options.pmd.rules.UnusedImports=true -options.pmd.rules.UnusedLocalVariable=true -options.pmd.rules.UnusedModifier=false -options.pmd.rules.UnusedNullCheckInEquals=true -options.pmd.rules.UnusedPrivateField=true -options.pmd.rules.UnusedPrivateMethod=true -options.pmd.rules.UseArrayListInsteadOfVector=false -options.pmd.rules.UseArraysAsList=false -options.pmd.rules.UseAssertEqualsInsteadOfAssertTrue=false -options.pmd.rules.UseAssertNullInsteadOfAssertTrue=false -options.pmd.rules.UseAssertSameInsteadOfAssertTrue=false -options.pmd.rules.UseCollectionIsEmpty=false -options.pmd.rules.UseCorrectExceptionLogging=false -options.pmd.rules.UseEqualsToCompareStrings=true -options.pmd.rules.UseIndexOfChar=true -options.pmd.rules.UseLocaleWithCaseConversions=false -options.pmd.rules.UseNotifyAllInsteadOfNotify=false -options.pmd.rules.UseProperClassLoader=false -options.pmd.rules.UseSingleton=false -options.pmd.rules.UseStringBufferForStringAppends=false -options.pmd.rules.UseStringBufferLength=true -options.pmd.rules.UselessOperationOnImmutable=true -options.pmd.rules.UselessOverridingMethod=true -options.pmd.rules.UselessStringValueOf=true -options.pmd.rules.VariableNamingConventions=false -options.pmd.rules.WhileLoopsMustUseBraces=false diff --git a/pmd-jedit/PMDPlugin/description.html b/pmd-jedit/PMDPlugin/description.html deleted file mode 100644 index cb517cbd9e..0000000000 --- a/pmd-jedit/PMDPlugin/description.html +++ /dev/null @@ -1,3 +0,0 @@ - -

PMD is a Java source code analysis tool - it checks your code for unused fields, empty try/catch/finally/if/while blocks, unused method parameters, and stuff like that. There's much more info at http://pmd.sf.net/. Share and enjoy!

- diff --git a/pmd-jedit/PMDPlugin/doc/changelog.txt b/pmd-jedit/PMDPlugin/doc/changelog.txt deleted file mode 100644 index d723e81914..0000000000 --- a/pmd-jedit/PMDPlugin/doc/changelog.txt +++ /dev/null @@ -1,99 +0,0 @@ -2007-11-20 - 2.7 - Changelog is now in ../jedit.html (the documentation). No need to duplicate - it, now is there? - -10th January 2006 - 2.6O -- Updated to PMD 3.4 -- Updated to jEdit 4.3pre3 version. -- Added "Ignore Literals & identifiers" option for CPD. - -16th August 2004 - 2.5 -- Updated to PMD 1.9 -- Removed Recursive Directory options and integrated them into FileChooser itself. -- Complete redesign of the way PMD Rules and Copy/Paste Detector are used. -- Fixed improper highlighting of Rule Violations. Because of this bug, any open file in jEdit was showing errors of other files too. -- Lots of code cleanup and optimizations. - -22 March 2004- 2.4 -- Optimized usage of ErrorSource for faster Error Highlighting. -- Fixed Run on save running when the buffer is non-Java. -- Updated to pmd 1.6 -- Added option to export PMD results to files in various formats such as HTML, XML, Text, CSV etc. -- Added a new feature to show Progressbar when working on Large file sets. -- Progressbar color configured via jEdit Properties. -- Improvements in Copy/Paste Detector - -October 31st 2003 - 2.3 -1. Updated to PMD 1.3 - -August 18th 2003 - 2.2 -1. Updated to PMD 1.2.1 -2. Updated to jEdit 4.2 API changes -3. Added PMD in jEdit's File System Browser Plugins Menu. - - -May 19th 2003 - 2.1: -Added "clear ErrorList" option - thanks to Randall Schultz for the suggestion. -Added "check all open buffers" option - thanks to Randall Schultz for the suggestion. -Added support to define Custom RuleSets thereby facilitating integration of Custom Rulesets with built-in rulesets & their independent development. -Added C/C++, PHP support to Copy/Paste Detector. Now you can find out duplicate code in your C/C++ & PHP code besides the usual Java code. - -April 18 2003 - 2.0: -Jiger Patel integrated CPD functionality. -Upgraded to work with pmd-1.05. - -March 24 2003 - 1.5: -Upgraded to work with pmd-1.04. - -February 11 2003 - 1.4: -Upgraded to work with pmd-1.03. - -January 24 2003 - 1.3: -Upgraded to work with pmd-1.02. - -November 20 2002 - 1.2: -Added some more fixes from Jiger. - -November 14 2002 - 1.1: -Added "directory popup option" feature; thanks to Jiger Patel for the suggestions. - -November 7 2002 - 1.0: -Updated to use pmd-1.01. - -October 4 2002 - 0.9: -Updated to use pmd-1.0rc3 - -Augst 16 2002 - 0.8: -Fixed GUI lockup problem -Added example text to option pane -Updated to use pmd-0.9 - -August 2 2002 - 0.7: -Updated to use pmd-0.8 -Now individual rules can be selected - -July 26 2002 - 0.6: -Updated to use pmd-0.7. -PMD can be run on 1) all files in a directory or 2) recursively into a directory tree. -Added some detail to the Options area. - -July 22 2002 - 0.5: -Moved options into Global Options area and made them look nicer. -Cleaned up menus. -Cleaned up help text. - -July 18 2002 - 0.4: -Updated to use pmd-0.6 -Modified to use ErrorList plugin -Fixed bug - displayed a popup if no messages are found - -July 12 2002 - 0.3: -Updated to use pmd-0.4. -Messages are displayed in a list. - -July 9 2002 - 0.2: -Fixed bug - a message, not an empty box, is now displayed if no errors are found. -Added options pane so rulesets are selectable and selections are persistant. - -July 8 2002 - 0.1: -Initial release diff --git a/pmd-jedit/PMDPlugin/doc/designer.jpg b/pmd-jedit/PMDPlugin/doc/designer.jpg deleted file mode 100644 index 8eac353c3e..0000000000 Binary files a/pmd-jedit/PMDPlugin/doc/designer.jpg and /dev/null differ diff --git a/pmd-jedit/PMDPlugin/doc/example_area.jpg b/pmd-jedit/PMDPlugin/doc/example_area.jpg deleted file mode 100644 index 3e6d83ebe6..0000000000 Binary files a/pmd-jedit/PMDPlugin/doc/example_area.jpg and /dev/null differ diff --git a/pmd-jedit/PMDPlugin/doc/jedit.html b/pmd-jedit/PMDPlugin/doc/jedit.html deleted file mode 100644 index 6eb2390288..0000000000 --- a/pmd-jedit/PMDPlugin/doc/jedit.html +++ /dev/null @@ -1,384 +0,0 @@ - - - - - PMD-JEdit Plug-in Users' Guide - - - - - -
-

- PMD-JEdit Plug-in User's Guide -

-
-
-

- PMD is a Java source code analyzer - it finds unused variables, questionable design decisions, empty catch blocks, and so forth. You can read much more about PMD here - http://pmd.sf.net/. -

-

- Actions -

-

- The various actions provided by this plugin are available on the 'PMD' menu item in the Plugins menu. This has several submenu options: -

- -

All those options put any errors into the ErrorList so you can then go jumping around your project fixing stuff. -

- There's a section in the Utilities->Global Options->Plugins configuration panel that lets you pick which rule sets you want to use. -

-

- Choose the rulesets you'd like to use: -
-
- -
-
- The checkbox tree makes it easy to pick complete rulesets, just check on a ruleset to select all the rules in a ruleset. You can also add your own custom rulesets by entering the path to your rules.xml file. Probably most handy for day-to-day use are the Basic, Import, and Unused Code rulesets. -
-
- The first time you install the PMD plugin, a number of rules are already selected. The selected rules are those suggested by PMD best practices -- unused code, basic rules, a few design rules, a few controversial rules, the imports rules, and the string rules. These are a good starting place. Feel free to add or remove rules as fits your needs. -
-
- -
-
- As you move your mouse over the various rules, the "Example" area shows the sort of code the particular rule checks for: -
-
- -
-
- The configuration area also contains settings for a few other things: -
-
- -
-
- These should be pretty much self-explanatory. One non-obvious thing is that if you check "Run PMD on Save", this will cause PMD to start automatically when jEdit starts. This is so PMD is ready to check your code the first time you save. This might cause jEdit to start just a little bit slower, but you probably won't notice that. -

- -

Note that the configuration panel also contains the minimum tile size for CPD to turn up a duplicate chunk. Take a look at the Release Notes and Changelogfor more details on new features in this release. -
-

- CPD, the Copy/Paste Detector -

- The PMD plugin provides access to the Copy/Paste Detector. This can help identify and eliminate duplicate code in a project. The heuristics used in the detection are a little "fuzzy" in that it is able to detect code that is very close to the same as code found elsewhere and can identify duplicate code regardless of the formatting of whitespace. -

- The CPD is very fast. It can also work on a variety of languages. Currently the fully supported languages are Java, JSP, PHP, C/C++, Fortran, Ruby, and Javascript. Additionally, CPD can work with just about every file mode supported by jEdit, although results may not be perfect as the modes not specifically supported use a generic tokenizer that may not suitable for a particular language. -

- A new feature for running CPD in a directory is the ability to include files as specified by a regular expression. This makes it easy to narrow your search in a project that may have a lot of files with the same name. -

- Another new feature for running CPD in a directory is the ability to exclude files. This makes it much easier to run CPD on a high level directory in a Maven project so the files in the "target" directories can be skipped. Enter a regular expression in the "Exclusions" field in the directory chooser dialog. For Maven projects, enter .*?/target/.* to exclude all the "target" directories. The "Exclusions" regular expression works on the full path of a file, so this regex might not work in all cases (like maybe code for target.com?) -

- You can set both an inclusion regular expression and an exclusion regular expression. Files are first checked for inclusion then exclusion. This means the Maven example above is still valid. -

- Custom Rules -

-

- Starting 2.1, you can now add Custom Defined Rulesets with PMD plugin. Previously, if you want to use your own rulesets with the PMD plugin, you had to unjar the pmd.jar file & add your ruleset defination in the jar file & re-jar it & use it. But this procedure had to be repeated whenever a new PMD is out. But not anymore. Now you can simply point PMD plugin to your custom rulesets.xml file & drop your custom ruleset jars in either of jEdit jars directory(either system or user). Once this is done, you will be able to manipulate your Custom Rulesets just the way like the built-in ones. -

-

- As of version 3.0, the PMD Plugin provides access to the PMD Rule Designer, which makes it easier to create your own custom rules. Start the Designer by going to Plugins -> PMD Plugin -> Run Rule Designer. The instructions for the Designer can be found on the PMD website at http://pmd.sourceforge.net/xpathruletutorial.html. -
-
- PMD Rule Designer: -
-
- -

-

- PMD jEdit 2.2 adds updates PMD plugin to the latest and the greatest PMD release, updates to Dynamic class loading feature of jEdit and adds PMD to jEdit's File System Browser for easy access. -

- -

- PMD jEdit plugin 2.5 updates to the latest PMD release, remove redundant menu options and makes usage of the plugin more compact. Look at the details Release notes and Changelog below. -

- - -

- Release Notes & Changelog -

- -

- 5.0.1 (Dale Anson, December 2012) -

-
    -
  1. - Updated to use the latest code from PMD 5.0.1, which includes rules for checking Java, JSP, JSF, Ecmascript, and XML. -
  2. -
  3. - Adjusted options: - -
  4. -
  5. - Adjusted rules by removing the jsp tab. All rules for all supported languages are in the same rules checkbox tree. -
  6. -
- -

- 3.4 (Dale Anson, June 2011) -

-
    -
  1. - Updated to use latest code from PMD 4.2.x branch, which includes a significant update to CPD. -
  2. -
  3. - Added ability to use an "exclusions" regular expression in CPD. -
  4. -
  5. - Added ability to save the output from a CPD run as a text file. -
  6. -
- -

- 3.3 (Dale Anson, June 2010) -

-
    -
  1. - Added ability to export the current ruleset. -
  2. -
  3. - Added a new option pane to allow the user to select custom rulesets. -
  4. -
  5. - Now using layout manager from Common Controls. -
  6. -
  7. - Now checking buffer mode rather than filename extension to know how to parse the file. -
  8. -
  9. - Improved display of rule priority and examples. -
  10. -
  11. - Added ability to use the JSP rules so PMD can be used on JSP files. -
  12. -
- -

- 3.2 (Dale Anson, Dec 2009) -

-
    -
  1. - Upgraded to PMD 4.2.6. -
  2. -
  3. - Adjusted CPD to work with just about all file modes supported by jEdit. -
  4. -
  5. - Moved all hard-coded strings to the property file so they can be localized. -
  6. -
-

- 3.1 (Dale Anson) -

-
    -
  1. - Display rule description along with example. -
  2. -
-

- 3.0 (Dale Anson) -

-
    -
  1. - Split the option pane into smaller panes so they are easier to use. -
  2. -
  3. - Selected some default rules for first-time users. This makes it much easier for new users to get started. -
  4. -
  5. - Changed plugin to start on jEdit startup and to check on file save. This makes it easier for PMD to be useful right away. -
  6. -
  7. - Upgraded to PMD 4.2.5, which includes some new rulesets, including one specifically for Android programming. -
  8. -
  9. - Mouse-over on ruleset names now gives description of the ruleset in the example box. This makes it easier to understand what the group of rules is about. -
  10. -
  11. - Added menu item to access PMD Rule Designer. -
  12. -
-

- 2.9 (2008-04-04, Dale Anson) -

-
    -
  1. - Fixed a bug in 'check all files in a directory' where the plugin always defaulted to Java 1.4 rather than the Java version selected in the option pane. -
  2. -
  3. - Revised the option pane to use a checkbox tree rather than a list of checkboxes. The list was long (just under 200 rules), and didn't have any grouping by ruleset. The checkbox tree groups the rules by ruleset, and clicking the checkbox on the ruleset checks all rules contained by that ruleset. This is way easier than looking through the long list to pick out the rules. -
  4. -
  5. - Revised the option pane so the layout is more compact and fits on the screen better. -
  6. -
-

- 2.7 (2007-11-20) -

-
    -
  1. - Updated to PMD 4.1 -
  2. -
  3. - New option: choose version of Java (1.4, 1.5, 1.6) -
  4. -
  5. - Fixed Bug [1501422] PMD Plugin: example box is not updated when new items hover filed in jEdit Plugins Bug tracker. -
  6. -
  7. - Changed the way Rules are managed and given for execution to PMD due to addition of new languages to PMD and was giving error due to language mismatch. -
  8. -
  9. - Added new option "Print Rulename in ErrorList" which is helpful to trace down what rule is generating this error. -
  10. -
-

- 2.6 -

-
    -
  1. - Updated to PMD 3.4 -
  2. -
  3. - Updated to jEdit 4.3pre3 -
  4. -
  5. - Added "Ignore Literals & identifiers" option for CPD. -
  6. -
-

- 2.5 -

-
    -
  1. - Updated to PMD 1.9 -
  2. -
  3. - Removed Recursive Directory options and integrated them into FileChooser itself. -
  4. -
  5. - Complete redesign of the way PMD Rules and Copy/Paste Detector are used. -
  6. -
  7. - Fixed improper highlighting of Rule Violations. Because of this bug, any open file in jEdit was showing errors of other files too. -
  8. -
  9. - Lots of code cleanup and optimizations. -
  10. -
- -

- 2.4 -

-
    -
  1. - Optimized usage of ErrorSource for faster Error Highlighting. -
  2. -
  3. - Updated to PMD 1.6 -
  4. -
  5. - Fixed Run on save running when the buffer is non Java also. -
  6. -
  7. - Added option to export PMD results to a file in various formats such as HTML, XML, Text, CSV etc. -
  8. -
  9. - Added a new feature to show Progressbar when working on Large file sets. -
  10. -
  11. - Made Progress bar color user-configurable. -
  12. -
  13. - Improvement in Copy/Paste Detector. -
  14. - -
-

- 2.3 -

-
    -
  1. - Updated to PMD 1.3 -
  2. -
-

- 2.2 -

-
    -
  1. - Updated to PMD 1.2.1 -
  2. -
  3. - Updated to jEdit 4.2 API changes -
  4. -
  5. - Added PMD in jEdit's File System Browser Plugins Menu. -
  6. -
-

- 2.1 -

-
    -
  1. - Added "clear ErrorList" option. -
  2. -
  3. - Added "check all open buffers" option. -
  4. -
  5. - Added support to define Custom RuleSets thereby facilitating integration of Custom Rulesets with built-in rulesets & their independent development. -
  6. -
  7. - Added C/C++, PHP support to Copy/Paste Detector. Now you can find out duplicate code in your C/C++ & PHP code besides the usual Java code. -
  8. -
-

- 2.0 -

-
    -
  1. - Integrated Copy/Paste Detector(CPD) in jEdit. -
  2. -
  3. - Updated to use pmd-1.05 -
  4. -
-

- Old change log -

- Old change log -

- License -

-

- The PMD-JEdit plugin is free software released under the Apache license. -

- - diff --git a/pmd-jedit/PMDPlugin/doc/other_settings.jpg b/pmd-jedit/PMDPlugin/doc/other_settings.jpg deleted file mode 100644 index 7ead5ffe88..0000000000 Binary files a/pmd-jedit/PMDPlugin/doc/other_settings.jpg and /dev/null differ diff --git a/pmd-jedit/PMDPlugin/doc/rules.jpg b/pmd-jedit/PMDPlugin/doc/rules.jpg deleted file mode 100644 index 00c528c76f..0000000000 Binary files a/pmd-jedit/PMDPlugin/doc/rules.jpg and /dev/null differ diff --git a/pmd-jedit/PMDPlugin/doc/ruleset.jpg b/pmd-jedit/PMDPlugin/doc/ruleset.jpg deleted file mode 100644 index e0581e0628..0000000000 Binary files a/pmd-jedit/PMDPlugin/doc/ruleset.jpg and /dev/null differ diff --git a/pmd-jedit/PMDPlugin/dockables.xml b/pmd-jedit/PMDPlugin/dockables.xml deleted file mode 100644 index 294912f7bf..0000000000 --- a/pmd-jedit/PMDPlugin/dockables.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - new net.sourceforge.pmd.jedit.CPDDuplicateCodeViewer(view); - - diff --git a/pmd-jedit/PMDPlugin/lib/asm-3.2.jar b/pmd-jedit/PMDPlugin/lib/asm-3.2.jar deleted file mode 100644 index 334e7fdc7f..0000000000 Binary files a/pmd-jedit/PMDPlugin/lib/asm-3.2.jar and /dev/null differ diff --git a/pmd-jedit/PMDPlugin/lib/jaxen-1.1.1.jar b/pmd-jedit/PMDPlugin/lib/jaxen-1.1.1.jar deleted file mode 100644 index b63363113f..0000000000 Binary files a/pmd-jedit/PMDPlugin/lib/jaxen-1.1.1.jar and /dev/null differ diff --git a/pmd-jedit/PMDPlugin/lib/pmd-5.1.0.jar b/pmd-jedit/PMDPlugin/lib/pmd-5.1.0.jar deleted file mode 100644 index 2a1ad1046c..0000000000 Binary files a/pmd-jedit/PMDPlugin/lib/pmd-5.1.0.jar and /dev/null differ diff --git a/pmd-jedit/PMDPlugin/services.xml b/pmd-jedit/PMDPlugin/services.xml deleted file mode 100644 index 08ecefccea..0000000000 --- a/pmd-jedit/PMDPlugin/services.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - new net.sourceforge.pmd.jedit.PMDProgressWidgetFactory(); - - diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/BufferDataSource.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/BufferDataSource.java deleted file mode 100644 index 49b5cc6e0a..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/BufferDataSource.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.sourceforge.pmd.jedit; - -import java.io.*; -import net.sourceforge.pmd.util.datasource.DataSource; -import org.gjt.sp.jedit.Buffer; - -/** - * A datasource that uses a Buffer as the source for the bytes. - */ -public class BufferDataSource implements DataSource { - - Buffer buffer = null; - - /** - * @param buffer The buffer to use as the data source. - */ - public BufferDataSource(Buffer buffer) { - if (buffer == null) { - throw new IllegalArgumentException("buffer is not allowed to be null"); - } - this.buffer = buffer; - } - - /** - * @return A buffered input stream containing the contents of the given buffer. - */ - public InputStream getInputStream() { - return new BufferedInputStream(new ByteArrayInputStream(buffer.getText().getBytes())); - } - - /** - * @param shortNames Not used. - * @param inputFileName Not used. - * @return The path and file name of the buffer, as returned by Buffer.getPath(). - */ - public String getNiceFileName(boolean shortNames, String inputFileName) { - return buffer.getPath(); - } -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java deleted file mode 100644 index a89399efc9..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java +++ /dev/null @@ -1,203 +0,0 @@ -package net.sourceforge.pmd.jedit; - -// Imports -import org.gjt.sp.jedit.Buffer; -import org.gjt.sp.jedit.View; -import org.gjt.sp.jedit.io.VFSManager; -import org.gjt.sp.jedit.jEdit; -import org.gjt.sp.jedit.textarea.Selection; -import org.gjt.sp.jedit.browser.VFSBrowser; -import org.gjt.sp.jedit.GUIUtilities; - -import java.awt.event.*; -import java.io.*; - -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTree; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeSelectionModel; -import java.awt.BorderLayout; -// End of Imports - -/** - * A GUI Component to display Duplicate code. - * - * @created 05 Apr 2003 - * @author Jiger Patel - * - */ - -public class CPDDuplicateCodeViewer extends JPanel { - JTree tree; - DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode("CPD Results", true)); - View view; - - public CPDDuplicateCodeViewer(View view) { - this.view = view; - setLayout(new BorderLayout()); - tree = new JTree(treeModel); - tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - tree.addTreeSelectionListener(new TreeSelectionListener() { - public void valueChanged(TreeSelectionEvent e) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); - if (node != null && node.isLeaf() && node instanceof Duplicate) { - Duplicate duplicate = (Duplicate) node; - gotoDuplicate(duplicate); - } - } - } - ); - add(new JScrollPane(tree)); - - JButton saveBtn = new JButton("Save"); - JPanel btnPanel = new JPanel(); - btnPanel.add(saveBtn); - add(btnPanel, BorderLayout.SOUTH); - saveBtn.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent ae) { - String[] dirs = GUIUtilities.showVFSFileDialog(CPDDuplicateCodeViewer.this.view, System.getProperty("user.home"), VFSBrowser.SAVE_DIALOG, false); - if (dirs != null && dirs.length > 0) { - String filename = dirs[0]; - File f = new File(filename); - writeTree(f); - } - } - } - ); - - } - - public void refreshTree() { - treeModel.reload(); - } - - private void writeTree(File file) { - try { - String output = getTreeAsText(); - BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - writer.write(output); - writer.close(); - } catch (IOException ioe) { - ioe.printStackTrace(); - } - } - - private String getTreeAsText() { - StringBuilder sb = new StringBuilder(128); - sb.append("CPD Results\n"); - DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot(); - for (int i = 0; i < root.getChildCount(); i++) { - DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt(i); - sb.append(child.toString()).append('\n'); - for (int j = 0; j < child.getChildCount(); j++) { - sb.append('\t').append(child.getChildAt(j)).append('\n'); - } - } - return sb.toString(); - } - - public void gotoDuplicate(final Duplicate duplicate) { - if (duplicate != null) { - final Buffer buffer = jEdit.openFile(view, duplicate.getFilename()); - - VFSManager.runInAWTThread(new Runnable() { - public void run() { - view.setBuffer(buffer); - - int start = buffer.getLineStartOffset(duplicate.getBeginLine() - 1); - int end = buffer.getLineEndOffset(Math.min(duplicate.getEndLine(), buffer.getLineCount() - 1)); - // Log.log(Log.DEBUG, this.getClass(), "Start Line "+ duplicate.getBeginLine() + " End Line "+ duplicate.getEndLine() + " Start " + start + " End "+ end); - // Since an AIOOB Exception is thrown if the end is the end of file. we do a -1 from end to fix it. - view.getTextArea().setSelection(new Selection.Range(start, end - 1)); - view.getTextArea().moveCaretPosition(start); - } - } - ); - } - } - - public DefaultMutableTreeNode getRoot() { - return (DefaultMutableTreeNode) treeModel.getRoot(); - } - - public void addDuplicates(Duplicates duplicates) { - // System.out.println("Inside addDuplicates " + duplicates +" Root child count "+ treeModel.getChildCount(treeModel.getRoot())); - getRoot().add(duplicates); - // vecDuplicates.addElement(duplicates); - } - - public class Duplicates extends DefaultMutableTreeNode { - // List vecduplicate = new ArrayList(); - String message, sourcecode; - - public Duplicates(String message, String sourcecode) { - this.message = message; - this.sourcecode = sourcecode; - } - - public String getSourceCode() { - return sourcecode; - } - - public void addDuplicate(Duplicate duplicate) { - add(duplicate); - // vecduplicate.addElement(duplicate); - } - - public String toString() { - return message; - } - } - - public class Duplicate extends DefaultMutableTreeNode { - private final String filename; - private final int beginLine, endLine; - - public Duplicate(String filename, int beginLine, int endLine) { - this.filename = filename; - this.beginLine = beginLine; - this.endLine = endLine; - } - - public String getFilename() { - return filename; - } - - public int getBeginLine() { - return beginLine; - } - - public int getEndLine() { - return endLine; - } - - public String toString() { - return filename + ":" + (getBeginLine()) + "-" + (getEndLine()); - } - } - - public void expandAll() { - int row = 0; - while (row < tree.getRowCount()) { - tree.expandRow(row); - row++; - } - } - - public void collapseAll() { - int row = tree.getRowCount() - 1; - while (row >= 0) { - tree.collapseRow(row); - row--; - } - } - - public void clearDuplicates() { - getRoot().removeAllChildren(); - } -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDFileFilter.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDFileFilter.java deleted file mode 100644 index a76374dd51..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDFileFilter.java +++ /dev/null @@ -1,127 +0,0 @@ -package net.sourceforge.pmd.jedit; - -import java.io.File; -import java.util.regex.*; -import javax.swing.filechooser.FileFilter; -import org.gjt.sp.util.Log; - -/** - * This is a file filter for CPD. I wanted to use a FileNameExtension filter, but - * Java 1.5 doesn't have a FileNameExtensionFilter, so this one is pretty close. - * One difference is I've added "mode" as a parameter to the constructor to make - * it easy to match a filter against a supported language in CPD. - */ -public class CPDFileFilter extends FileFilter implements Comparable, java.io.FilenameFilter { - - private String mode; - private String description; - private String[] extensions; - private Pattern inclusionsPattern = null; - private Pattern exclusionsPattern = null; - - /** - * @param mode A language known to CPD. So far, these line up nicely with - * the mode names in jEdit, e.g. "java" = "java". - * @param description Some text to show in the "Files of Type" drop down in - * a JFileChooser. - * @param extensions A list of file name extensions supported by this filter. - */ - public CPDFileFilter(String mode, String description, String... extensions) { - this.mode = mode; - this.description = description; - this.extensions = extensions; - } - - public void setInclusions(String regex) { - if (regex != null && regex.length() > 0) { - inclusionsPattern = Pattern.compile(regex); - } - } - - public void setExclusions(String regex) { - if (regex != null && regex.length() > 0) { - exclusionsPattern = Pattern.compile(regex); - } - } - - /** - * @param f A file to check to see if this filter will accept it. - * @return true if the file is acceptable. - */ - public boolean accept(File f) { - if (f == null) { - return false; - } - - // always accept directories so JFileChooser works correctly - if (f.isDirectory()) { - return true; - } - - // check full path for inclusions - if (inclusionsPattern != null) { - Matcher m = inclusionsPattern.matcher(f.getAbsolutePath()); - if (!m.matches()) { - return false; - } - } - - // check full path for exclusions - if (exclusionsPattern != null) { - Matcher m = exclusionsPattern.matcher(f.getAbsolutePath()); - if (m.matches()) { - return false; - } - } - - Log.log(Log.DEBUG, this, "CPD checking: " + f.getAbsolutePath()); - - // check the extension against acceptable extensions - String name = f.getName(); - for (String ext : extensions) { - // The CPD file filter converts all extensions to upper case - if (name.toUpperCase().endsWith(ext)) { - return true; - } - } - - // no match - return false; - } - - public boolean accept(File dir, String name) { - return accept(new File(dir, name)); - } - - public String getDescription() { - return description; - } - - public String getMode() { - return mode; - } - - public String[] getExtensions() { - return extensions; // NOPMD - } - - public int compareTo(CPDFileFilter filter) { - if (filter == null) { - return -1; - } - return toString().compareTo(filter.toString()); - } - - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(description); - sb.append(" ("); - for (String s : extensions) { - sb.append(s).append(','); - } - sb.deleteCharAt(sb.lastIndexOf(",")); - sb.append(')'); - - return sb.toString(); - } -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDOptionPane.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDOptionPane.java deleted file mode 100644 index 70c7defd2c..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDOptionPane.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * User: tom - * Date: Jul 8, 2002 - * Time: 4:29:19 PM - */ -package net.sourceforge.pmd.jedit; - - -import org.gjt.sp.jedit.AbstractOptionPane; -import org.gjt.sp.jedit.OptionPane; -import org.gjt.sp.jedit.jEdit; - -import java.awt.FlowLayout; -import javax.swing.BorderFactory; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import javax.swing.text.AbstractDocument; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.DocumentFilter; -import javax.swing.text.DocumentFilter.FilterBypass; - -import ise.java.awt.KappaLayout; - -public class CPDOptionPane extends AbstractOptionPane implements OptionPane { - - - private JCheckBox chkIgnoreLiterals; - - JTextField txtMinTileSize; - - JComboBox comboRenderer; - - public CPDOptionPane() { - super(PMDJEditPlugin.NAME); - } - - public void _init() { - removeAll(); - setLayout(new FlowLayout(FlowLayout.LEFT)); - - JPanel panel = new JPanel(new KappaLayout()); - panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); - - JLabel title = new JLabel("" + jEdit.getProperty("cpd-viewer.label", "Copy/Paste Detector")); - - chkIgnoreLiterals = new JCheckBox(jEdit.getProperty("net.sf.pmd.Ignore_Literals_&_identifiers_when_detecting_Duplicate_Code", "Ignore Literals & identifiers when detecting Duplicate Code"), jEdit.getBooleanProperty(PMDJEditPlugin.IGNORE_LITERALS)); - - JLabel lblMinTileSize = new JLabel(jEdit.getProperty("net.sf.pmd.Minimum_Tile_Size>", "Minimum Tile Size:")); - // TODO: add a document that only accepts numbers - txtMinTileSize = new JTextField(jEdit.getProperty(PMDJEditPlugin.DEFAULT_TILE_MINSIZE_PROPERTY, "100"), 5); - ((AbstractDocument) txtMinTileSize.getDocument()).setDocumentFilter(new NumericDocumentFilter()); - - JLabel lblRenderer = new JLabel(jEdit.getProperty("net.sf.pmd.Export_Output_as_", "Export output as: ")); - comboRenderer = new JComboBox(new String [] { "None", "Text", "Html", "XML", "CSV"} ); - comboRenderer.setSelectedItem(jEdit.getProperty(PMDJEditPlugin.RENDERER)); - - panel.add("0, 0, 2, 1, W, w, 3", title); - panel.add("0, 1, 2, 1, W, w, 3", chkIgnoreLiterals); - panel.add("0, 2, 1, 1, W, w, 3", lblMinTileSize); - panel.add("1, 2, 1, 1, W, w, 3", txtMinTileSize); - panel.add("0, 3, 1, 1, W, w, 3", lblRenderer); - panel.add("1, 3, 1, 1, W, w, 3", comboRenderer); - - - add(panel); - } - - public void _save() { - jEdit.setBooleanProperty(PMDJEditPlugin.IGNORE_LITERALS, chkIgnoreLiterals.isSelected()); - jEdit.setIntegerProperty(PMDJEditPlugin.DEFAULT_TILE_MINSIZE_PROPERTY, (txtMinTileSize.getText().length() == 0) ? 100 : Integer.parseInt(txtMinTileSize.getText())); - jEdit.setProperty(PMDJEditPlugin.RENDERER, (String) comboRenderer.getSelectedItem()); - } - - class NumericDocumentFilter extends DocumentFilter { - public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { - if (string == null) { - return ; - } - - if (isNumeric(string)) { - super.insertString(fb, offset, string, attr); - } - } - - public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException { - super.remove(fb, offset, length); - } - - public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { - if (text == null) { - return ; - } - - if (isNumeric(text)) { - super.replace(fb, offset, length, text, attrs); - } - } - - private boolean isNumeric(String string) { - for (char c : string.toCharArray()) { - if (! Character.isDigit(c)) { - return false; - } - } - return true; - } - } -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/ErrorListRenderer.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/ErrorListRenderer.java deleted file mode 100644 index eab762e879..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/ErrorListRenderer.java +++ /dev/null @@ -1,76 +0,0 @@ -package net.sourceforge.pmd.jedit; - -import java.io.IOException; -import java.util.Iterator; - -import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.renderers.AbstractIncrementingRenderer; - -import org.gjt.sp.jedit.jEdit; - -import errorlist.DefaultErrorSource; -import errorlist.ErrorSource; - -/** - * Renderer to ErrorList. - */ -public class ErrorListRenderer extends AbstractIncrementingRenderer { - - public static final String NAME = "errorlist"; - - DefaultErrorSource errorSource = null; - - /** - * @param errorSource The error source to send errors to. - */ - public ErrorListRenderer( DefaultErrorSource errorSource ) { - super( NAME, "ErrorList" ); - this.errorSource = errorSource; - - // nothing will ever be written to this writer - setWriter(new NullWriter()); - } - - /** - * @return Always returns an empty string. - */ - public String defaultFileExtension() { - return ""; - } - - /** - * Does nothing. - */ - @Override - public void start() throws IOException { - } - - /** - * Sends the rule violations to the ErrorList plugin. - */ - @Override - public void renderFileViolations( Iterator violations ) throws IOException { - if (!violations.hasNext()) { - errorSource.clear(); - return; - } - - String rulename = ""; - final boolean showRuleName = jEdit.getBooleanProperty( PMDJEditPlugin.PRINT_RULE ); - - while ( violations.hasNext() ) { - RuleViolation violation = violations.next(); - if ( showRuleName ) { - rulename = violation.getRule().getName() + "->"; - } - - // error list doesn't handle multi-line errors, so in the case of a - // multi-line violation, use 0 for the start and end columns. ErrorList - // will mark the entire line as an error. - int startLine = violation.getBeginLine() - 1; - int startColumn = violation.getBeginLine() == violation.getEndLine() ? violation.getBeginColumn() - 1: 0; - int endColumn = violation.getBeginLine() == violation.getEndLine() ? violation.getEndColumn() : 0; - errorSource.addError( new DefaultErrorSource.DefaultError( errorSource, ErrorSource.WARNING, violation.getFilename(), startLine, startColumn, endColumn, rulename + violation.getDescription() ) ); // NOPMD - } - } -} diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/FileDataSource.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/FileDataSource.java deleted file mode 100644 index c97fca2405..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/FileDataSource.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ -package net.sourceforge.pmd.jedit; - -import java.io.*; -import net.sourceforge.pmd.util.datasource.DataSource; - -/** - * DataSource implementation to read data from a file. This one is different than - * the one provided by PMD in that it uses buffering and gives access to the file - * directly. - */ -public class FileDataSource implements DataSource { - - private static final String FILE_SEPARATOR = System.getProperty("file.separator"); - - private File file; - - /** - * @param file the file to read - */ - public FileDataSource(File file) { - this.file = file; - } - - public InputStream getInputStream() throws IOException { - return new BufferedInputStream(new FileInputStream(file)); - } - - public void setFile(File file) { - this.file = file; - } - - public File getFile() { - return file; - } - - public String getNiceFileName(boolean shortNames, String inputFileName) { - return glomName(shortNames, inputFileName, file); - } - - private String glomName(boolean shortNames, String inputFileName, File file) { - if (shortNames && inputFileName.indexOf(',') == -1) { - if (new File(inputFileName).isDirectory()) { - return trimAnyPathSep(file.getAbsolutePath().substring(inputFileName.length())); - } else { - if (inputFileName.indexOf(FILE_SEPARATOR.charAt(0)) == -1) { - return inputFileName; - } - return trimAnyPathSep(inputFileName.substring(inputFileName.lastIndexOf(FILE_SEPARATOR))); - } - } - - try { - return file.getCanonicalFile().getAbsolutePath(); - } catch (Exception e) { - return file.getAbsolutePath(); - } - } - - private String trimAnyPathSep(String name) { - - return name.startsWith(FILE_SEPARATOR) ? - name.substring(1) : - name; - } -} diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/NullWriter.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/NullWriter.java deleted file mode 100644 index 6b82deb664..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/NullWriter.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.sourceforge.pmd.jedit; - -import java.io.Writer; -import java.io.IOException; - -/** - * A bottomless sink. This writer doesn't write anything, it simply ignores any - * input to any method. No exceptions will actually be thrown from this class. - * This is useful for situations where a writer is required, but there isn't any - * need to actually do any writing. - */ -public class NullWriter extends Writer { - - public void close() throws IOException { - } - - public void flush() throws IOException { - } - - public void write(char[] buffer, int offset, int length) throws IOException { - } -} diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDGeneralOptionPane.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDGeneralOptionPane.java deleted file mode 100644 index 35ae36004e..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDGeneralOptionPane.java +++ /dev/null @@ -1,72 +0,0 @@ -/* -* User: tom -* Date: Jul 8, 2002 -* Time: 4:29:19 PM -*/ -package net.sourceforge.pmd.jedit; - - -import org.gjt.sp.jedit.AbstractOptionPane; -import org.gjt.sp.jedit.OptionPane; -import org.gjt.sp.jedit.jEdit; - -import java.awt.FlowLayout; -import javax.swing.BorderFactory; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JPanel; - -import ise.java.awt.KappaLayout; - - -public class PMDGeneralOptionPane extends AbstractOptionPane implements OptionPane { - - - private JCheckBox chkRunPMDOnSave, chkClearErrorListOnSave, chkShowProgressBar, chkPrintRule; - - - public PMDGeneralOptionPane() { - super( PMDJEditPlugin.NAME ); - } - - public void _init() { - removeAll(); - setLayout(new FlowLayout(FlowLayout.LEFT)); - - JPanel panel = new JPanel(new KappaLayout()); - panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); - - JLabel title = new JLabel("" + jEdit.getProperty("options.pmd.general.label", "PMD Settings")); - - chkRunPMDOnSave = new JCheckBox( jEdit.getProperty("net.sf.pmd.Run_PMD_on_Save", "Run PMD on Save"), jEdit.getBooleanProperty( PMDJEditPlugin.RUN_PMD_ON_SAVE ) ); - chkClearErrorListOnSave = new JCheckBox( jEdit.getProperty("net.sf.pmd.Clear_ErrorList_on_Save", "Clear ErrorList on Save"), jEdit.getBooleanProperty( PMDJEditPlugin.CLEAR_ERRORLIST_ON_SAVE ) ); - chkPrintRule = new JCheckBox( jEdit.getProperty("net.sf.pmd.Print_Rulename_in_ErrorList", "Print Rulename in ErrorList"), jEdit.getBooleanProperty( PMDJEditPlugin.PRINT_RULE ) ); - chkShowProgressBar = new JCheckBox( jEdit.getProperty("net.sf.pmd.Show_PMD_Progress_Bar", "Show PMD Progress Bar"), jEdit.getBooleanProperty( PMDJEditPlugin.SHOW_PROGRESS ) ); - - panel.add("0, 0, 1, 1, W, w, 3", title); - panel.add("0, 1, 1, 1, W, w, 3", chkRunPMDOnSave); - panel.add("0, 2, 1, 1, W, w, 3", chkClearErrorListOnSave); - panel.add("0, 3, 1, 1, W, w, 3", chkPrintRule); - panel.add("0, 4, 1, 1, W, w, 3", chkShowProgressBar); - - add( panel ); - } - - public void _save() { - // If the user has checked "Run PMD on save", set the plugin to load on jEdit - // start up so that the "run on save" feature works right away. Unchecking - // "Run PMD on save" sets the "activate" property back to "defer", which is - // the default. - boolean on_save = chkRunPMDOnSave.isSelected(); - jEdit.setBooleanProperty( PMDJEditPlugin.RUN_PMD_ON_SAVE, on_save ); - jEdit.setProperty( "plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.activate", on_save ? "startup" : "defer" ); - - jEdit.setBooleanProperty( PMDJEditPlugin.CLEAR_ERRORLIST_ON_SAVE, chkClearErrorListOnSave.isSelected() ); - jEdit.setBooleanProperty( PMDJEditPlugin.PRINT_RULE, chkPrintRule.isSelected() ); - - // adjust the status bar to show or hide the pmd progress widget. 'addProgressBar()' - // uses the SHOW_PROGRESS to decide if the bar should actually be shown. - jEdit.setBooleanProperty( PMDJEditPlugin.SHOW_PROGRESS, chkShowProgressBar.isSelected() ); - PMDJEditPlugin.addProgressBar(); - } -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java deleted file mode 100644 index c0f60cba97..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java +++ /dev/null @@ -1,908 +0,0 @@ -/* - * User: tom - * Date: Jul 3, 2002 - * Time: 2:33:24 PM -*/ -package net.sourceforge.pmd.jedit; - -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.awt.BorderLayout; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.*; -import java.util.*; -import java.util.regex.*; - -import javax.swing.*; -import javax.swing.border.EtchedBorder; -import javax.swing.tree.DefaultMutableTreeNode; - -import net.sourceforge.pmd.PMD; -import net.sourceforge.pmd.PMDConfiguration; -import net.sourceforge.pmd.Report; -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.RuleSets; -import net.sourceforge.pmd.cpd.CPD; -import net.sourceforge.pmd.cpd.CPDConfiguration; -import net.sourceforge.pmd.util.FileFinder; -import net.sourceforge.pmd.cpd.AnyLanguage; -import net.sourceforge.pmd.cpd.JavaTokenizer; -import net.sourceforge.pmd.cpd.Language; -import net.sourceforge.pmd.cpd.LanguageFactory; -import net.sourceforge.pmd.cpd.Match; -import net.sourceforge.pmd.cpd.TokenEntry; -import net.sourceforge.pmd.lang.LanguageVersion; -import net.sourceforge.pmd.renderers.CSVRenderer; -import net.sourceforge.pmd.renderers.HTMLRenderer; -import net.sourceforge.pmd.renderers.Renderer; -import net.sourceforge.pmd.renderers.TextRenderer; -import net.sourceforge.pmd.renderers.XMLRenderer; -import net.sourceforge.pmd.util.datasource.DataSource; -import net.sourceforge.pmd.util.designer.Designer; - -import org.gjt.sp.jedit.Buffer; -import org.gjt.sp.jedit.EBMessage; -import org.gjt.sp.jedit.EBPlugin; -import org.gjt.sp.jedit.GUIUtilities; -import org.gjt.sp.jedit.Mode; -import org.gjt.sp.jedit.ServiceManager; -import org.gjt.sp.jedit.View; -import org.gjt.sp.jedit.jEdit; -import org.gjt.sp.jedit.browser.VFSBrowser; -import org.gjt.sp.jedit.io.VFSFile; -import org.gjt.sp.jedit.msg.BufferUpdate; -import org.gjt.sp.jedit.syntax.ModeProvider; -import org.gjt.sp.util.Log; - -import errorlist.DefaultErrorSource; -import errorlist.ErrorSource; - -import ise.java.awt.KappaLayout; - -/** jEdit plugin for PMD - * @version $Id$ - * - * TODO: this really needs rewritten to move all the "instance" stuff to a new - * class. - **/ -public class PMDJEditPlugin extends EBPlugin { - - public static final String NAME = "PMD"; - public static final String CHECK_DIR_RECURSIVE = "pmd.checkDirRecursive"; - public static final String CUSTOM_RULES_ONLY_KEY = "pmd.customRulesOnly"; - public static final String CUSTOM_RULES_PATH_KEY = "pmd.customRulesPath"; - public static final String DEFAULT_TILE_MINSIZE_PROPERTY = "pmd.cpd.defMinTileSize"; - public static final String EXCLUDE_CUSTOM_RULES_KEY = "pmd.excludeCustomRules"; - public static final String IGNORE_LITERALS = "pmd.ignoreliterals"; - public static final String LAST_DIRECTORY = "pmd.cpd.lastDirectory"; - public static final String LAST_EXCLUSION_REGEX = "pmd.cpd.lastExclusionRegex"; - public static final String LAST_INCLUSION_REGEX = "pmd.cpd.lastInclusionRegex"; - public static final String LAST_SELECTED_FILTER = "pmd.cpd.lastSelectedFilter"; - public static final String OPTION_RULES_PREFIX = "options.pmd.rules."; - public static final String PRINT_RULE = "pmd.printRule"; - public static final String RUN_PMD_ON_SAVE = "pmd.runPMDOnSave"; - public static final String CLEAR_ERRORLIST_ON_SAVE = "pmd.clearErrorListOnSave"; - public static final String SHOW_PROGRESS = "pmd.showprogress"; - - private static PMDJEditPlugin instance; - private static PMDProgressWidgetFactory.ProgressWidget progressBar; - - private Map errorSources = new HashMap(); - public static final String RENDERER = "pmd.renderer"; - - private static int lastSelectedFilter = 0; - private static String lastInclusion = ""; - private static String lastExclusion = ""; - - public void start() { - instance = this; - // Log.log(Log.DEBUG,this,"Instance created."); - lastSelectedFilter = jEdit.getIntegerProperty( LAST_SELECTED_FILTER, 0 ); - lastInclusion = jEdit.getProperty( LAST_INCLUSION_REGEX, "" ); - lastExclusion = jEdit.getProperty( LAST_EXCLUSION_REGEX, "" ); - addProgressBar(); - } - - public void stop() { - instance = null; - unRegisterErrorSources(); - ServiceManager.unregisterService( "org.gjt.sp.jedit.gui.statusbar.StatusWidgetFactory", "pmd" ); - ServiceManager.unloadServices( getPluginJAR() ); - removeProgressBar(); - } - - public static void checkDirectory( View view ) { - instance.instanceCheckDirectory( view ); - } - - public void handleMessage( EBMessage ebmess ) { - // maybe run PMD on buffer save - if ( ebmess instanceof BufferUpdate && jEdit.getBooleanProperty( PMDJEditPlugin.RUN_PMD_ON_SAVE ) ) { - try { - BufferUpdate bu = ( BufferUpdate ) ebmess; - String modename = bu.getBuffer().getMode().getName(); - if ( bu.getWhat() == BufferUpdate.SAVED && ( "java".equals( modename ) || "jsp".equals( modename ) ) ) { - check( bu.getBuffer(), bu.getView() ); - } - } catch ( Exception e ) { // NOPMD - } - } - } - - // check all open buffers - public static void checkAllOpenBuffers( View view ) { - instance.instanceCheckAllOpenBuffers( view ); - } - - public void instanceCheckDirectory( final View view ) { - String[] paths = GUIUtilities.showVFSFileDialog( view, jEdit.getProperty( LAST_DIRECTORY ), VFSBrowser.CHOOSE_DIRECTORY_DIALOG, false ); - try { - File selectedFile = null; - - if ( paths != null && paths.length == 1 ) { - boolean recursive = JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog( view, "Recursively check subdirectories?", "Recursive", JOptionPane.YES_NO_OPTION ); - selectedFile = new File( paths[0] ); - - if ( ! selectedFile.isDirectory() ) { - DefaultErrorSource errorSource = getErrorSource( view ); - errorSource.addError( new DefaultErrorSource.DefaultError( errorSource, ErrorSource.ERROR, selectedFile.getAbsolutePath(), 0, 0, 0, jEdit.getProperty( "net.sf.pmd.Selection_not_a_directory.", "Selection not a directory." ) ) ); // NOPMD - return; - } - - jEdit.setProperty( LAST_DIRECTORY, selectedFile.getCanonicalPath() ); - jEdit.setBooleanProperty( CHECK_DIR_RECURSIVE, recursive ); - - process( selectedFile.getCanonicalPath(), view ); - } - } catch ( IOException e ) { - Log.log( Log.DEBUG, this, e ); - } - } - - public void instanceCheckAllOpenBuffers( final View view ) { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - Buffer buffers[] = jEdit.getBuffers(); - if ( buffers != null ) { - boolean showProgress = jEdit.getBooleanProperty( SHOW_PROGRESS ); - if ( showProgress ) { - startProgressBarDisplay( view, buffers.length ); - } - - for ( Buffer buffer : buffers ) { - instanceCheck( buffer, view, false ); - - if ( showProgress && instance.progressBar != null ) { - instance.progressBar.update(); - } - } - if ( showProgress ) { - endProgressBarDisplay(); - } - } - - } - } ); - } - - /** - * Runs the PMD rules on the given buffer. - * @param buffer The buffer to check. - * @param view The View displaying the buffer. - * @param clearErrorList Use true to clear the error list before displaying the results of this check. - */ - public void instanceCheck( Buffer buffer, View view, boolean clearErrorList ) { - - String modename = buffer.getMode().getName(); - LanguageVersion languageVersion = getLanguageVersion( modename ); - if ( languageVersion == null ) { - return; - } - - PMD pmd = new PMD(); - - // configure PMD to use the language parser for the buffer mode - PMDConfiguration configuration = pmd.getConfiguration(); - configuration.setDefaultLanguageVersion( languageVersion ); - - // get the rules to run - SelectedRules selectedRuleSets = new SelectedRules(); - RuleSets toCheck = selectedRuleSets.getSelectedRules(); - SelectedRulesRuleSetFactory ruleFactory = new SelectedRulesRuleSetFactory( toCheck ); - - // wrap the buffer in a data source so it can be read as a stream - BufferDataSource source = new BufferDataSource( buffer ); - List files = new ArrayList(); - files.add( source ); - - // set up the rule context with a report to gather the processing output - RuleContext ctx = new RuleContext(); - final Report report = new Report(); - ctx.setReport( report ); - String path = buffer.getPath(); - ctx.setSourceCodeFilename( path ); - ctx.setLanguageVersion( languageVersion ); - - // create an ErrorListRenderer that sends errors directly to ErrorList, - // doing so allows PMD use multiple threads if needed. - DefaultErrorSource errorSource = getErrorSource( view ); - if ( clearErrorList ) { - errorSource.clear(); - } - ErrorListRenderer errorListRenderer = new ErrorListRenderer( errorSource ); - List renderers = new ArrayList(); - renderers.add( errorListRenderer ); - - pmd.processFiles( configuration, ruleFactory, files, ctx, renderers ); - } - - public LanguageVersion getLanguageVersion( String modename ) { - if ( "java".equals( modename ) ) { - return LanguageVersion.JAVA_17; - } - if ( "c++".equals( modename ) ) { - return LanguageVersion.CPP; - } - if ( "javascript".equals( modename ) ) { - return LanguageVersion.ECMASCRIPT; - } - if ( "jsp".equals( modename ) ) { - return LanguageVersion.JSP; - } - if ( "php".equals( modename ) ) { - return LanguageVersion.PHP; - } - if ( "ruby".equals( modename ) ) { - return LanguageVersion.RUBY; - } - if ( "xml".equals( modename ) || "ant".equals( modename ) || "maven".equals( modename ) ) { - return LanguageVersion.XML; - } - if ( "xsl".equals( modename ) ) { - return LanguageVersion.XSL; - } - return null; - } - - /** - * Run PMD on a directory of files. Only files of a type supported by PMD will be - * checked. - * @param files A list of files to check. It is assumed that these files are of - * a type supported by PMD. - * @param view The view for the current instance of PMD. - */ - public void process( final List files, final View view ) { - processFiles( files, view ); - } - - /** - * Run PMD on a directory of files. Only files of a type supported by PMD will be - * checked. - * @param dirname The directory to search for files. Only supported files will be checked. - * @param view The view for the current instance of PMD. - */ - public void process( final String dirname, final View view ) { - SwingWorker, Object> sw = new SwingWorker, Object>() { - - @Override - public List doInBackground() { - List files = findFiles( dirname, true ); - return files; - } - - @Override - public void done() { - try { - List files = get(); - processFiles( files, view ); - } catch ( Exception e ) { - e.printStackTrace(); - } - } - }; - sw.execute(); - } - - // check current buffer - public static void check( Buffer buffer, View view ) { - instance.instanceCheck( buffer, view, jEdit.getBooleanProperty( CLEAR_ERRORLIST_ON_SAVE, false ) ); - } - - void processFiles( final List files, final View view ) { - SwingWorker sw = new SwingWorker() { - boolean showProgress = jEdit.getBooleanProperty( SHOW_PROGRESS ); - - @Override - public Object doInBackground() { - PMD pmd = new PMD(); - PMDConfiguration configuration = pmd.getConfiguration(); - configuration.setThreads(0 ); - RuleContext ctx = new RuleContext(); - - // get the rules to run - SelectedRules selectedRuleSets = new SelectedRules(); - RuleSets toCheck = selectedRuleSets.getSelectedRules(); - SelectedRulesRuleSetFactory ruleFactory = new SelectedRulesRuleSetFactory( toCheck ); - - // create an ErrorListRenderer that sends errors directly to ErrorList, - // doing so allows PMD use multiple threads if needed. - DefaultErrorSource errorSource = getErrorSource( view ); - errorSource.clear(); - ErrorListRenderer errorListRenderer = new ErrorListRenderer( errorSource ); - List renderers = new ArrayList(); - renderers.add( errorListRenderer ); - - if ( showProgress ) { - startProgressBarDisplay( view, files.size() ); - addPropertyChangeListener( new PropertyChangeListener() { - public void propertyChange( PropertyChangeEvent evt ) { - if ( "progress".equals( evt.getPropertyName() ) ) { - instance.progressBar.update(); - } - } - } ); - } - - // TODO: pmd.processFiles can handle multiple files at once, can I use that here? - // -- maybe, once the pmd.processFiles with the progress monitor is complete. - for ( int count = 0; count < files.size(); count++ ) { - File file = files.get( count ); - List fileToCheck = new ArrayList(); - fileToCheck.add( new FileDataSource( file ) ); - String modename = ModeProvider.instance.getModeForFile( file.getName(), "" ).getName(); - LanguageVersion languageVersion = getLanguageVersion( modename ); - - // configure PMD to use the language parser for the buffer mode - configuration.setDefaultLanguageVersion( languageVersion ); - - ctx.setLanguageVersion( languageVersion ); - ctx.setSourceCodeFile( file ); - ctx.setReport( new Report() ); - - pmd.processFiles( configuration, ruleFactory, fileToCheck, ctx, renderers ); - if ( showProgress && instance.progressBar != null ) { - setProgress( count ); - } - } - return null; - } - - @Override - public void done() { - if ( showProgress ) { - endProgressBarDisplay(); - } - } - }; - sw.execute(); - - } - - private List findFiles( String dir, boolean recurse ) { - FileFinder f = new FileFinder(); - FilenameFilter filter = new FilenameFilter() { - public boolean accept( File dir, String name ) { - File file = new File( dir, name ); - if ( file.isDirectory() ) { - return true; - } - Mode mode = ModeProvider.instance.getModeForFile( name, "" ); - String modename = mode == null ? "" : mode.getName(); - return getLanguageVersion( modename ) != null; - } - }; - return f.findFilesFrom( dir, filter, recurse ); - } - - private void unRegisterErrorSources() { - for ( DefaultErrorSource errorSource : errorSources.values() ) { - ErrorSource.unregisterErrorSource( errorSource ); - } - } - - private DefaultErrorSource getErrorSource( View view ) { - DefaultErrorSource errorSource = errorSources.get( view ); - if ( errorSource == null ) { - errorSource = new DefaultErrorSource( NAME, view ); - errorSources.put( view, errorSource ); - ErrorSource.registerErrorSource( errorSource ); - } - return errorSource; - } - - public static void cpdCurrentFile( View view ) throws IOException { - String modeName = getFileType( view.getBuffer().getMode().getName() ); - if ( modeName == null ) { - JOptionPane.showMessageDialog( view, jEdit.getProperty( "net.sf.pmd.Copy/Paste_detection_can_not_be_performed_on_this_file\nbecause_the_mode_can_not_be_determined.", "Copy/Paste detection can not be performed on this file\nbecause the mode can not be determined." ), jEdit.getProperty( "net.sf.pmd.Copy/Paste_Detector", "Copy/Paste Detector" ), JOptionPane.INFORMATION_MESSAGE ); - return; - } - instance.instanceCPDCurrentFile( view, view.getBuffer().getPath(), modeName ); - } - - public static void cpdCurrentFile( View view, VFSBrowser browser ) throws IOException { - VFSFile selectedFile[] = browser.getSelectedFiles(); - - if ( selectedFile == null || selectedFile.length == 0 ) { - JOptionPane.showMessageDialog( view, jEdit.getProperty( "net.sf.pmd.One_file_must_be_selected", "One file must be selected" ), NAME, JOptionPane.ERROR_MESSAGE ); - return; - } - - if ( selectedFile[0].getType() == VFSFile.DIRECTORY ) { - JOptionPane.showMessageDialog( view, jEdit.getProperty( "net.sf.pmd.Selected_file_cannot_be_a_Directory.", "Selected file cannot be a Directory." ), NAME, JOptionPane.ERROR_MESSAGE ); - return; - } - String path = selectedFile[0].getPath(); - instance.instanceCPDCurrentFile( view, path, getFileType( path ) ); - } - - // TODO: Replace this method with a smart file type/mode detector. - private static String getFileType( String name ) { - if ( name != null ) { - for ( String lang : LanguageFactory.supportedLanguages ) { - if ( name.endsWith( lang ) ) { - return lang; - } - - } - if ( name.endsWith( "h" ) || name.endsWith( "cxx" ) || name.endsWith( "c++" ) ) { - return "cpp"; - } - } - return name; - } - - private void instanceCPDCurrentFile( View view, String filename, String fileType ) throws IOException { - CPD cpd = getCPD( fileType ); - // Log.log(Log.DEBUG, PMDJEditPlugin.class , "See mode " + view.getBuffer().getMode().getName()); - - if ( cpd != null ) { - cpd.add( new File( filename ) ); - cpd.go(); - instance.processDuplicates( cpd, view ); - view.getDockableWindowManager().showDockableWindow( "cpd-viewer" ); - } else { - view.getStatus().setMessageAndClear( jEdit.getProperty( "net.sf.pmd.CPD_does_not_yet_support_this_file_type>_", "CPD does not yet support this file type: " ) + fileType ); - return; - } - } - - public static void cpdDir( View view ) { - JFileChooser chooser = new JFileChooser( jEdit.getProperty( LAST_DIRECTORY ) ); - chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ); - - JPanel pnlAccessory = new JPanel(); - pnlAccessory.setLayout( new KappaLayout() ); - - JLabel lblMinTileSize = new JLabel( jEdit.getProperty( "net.sf.pmd.Minimum_Tile_size_>", "Minimum Tile size :" ) ); - JTextField txttilesize = new JTextField(3 ); - txttilesize.setText( jEdit.getIntegerProperty( DEFAULT_TILE_MINSIZE_PROPERTY, 100 ) + "" ); - - JCheckBox chkRecursive = new JCheckBox( jEdit.getProperty( "net.sf.pmd.Recursive", "Recursive" ), jEdit.getBooleanProperty( CHECK_DIR_RECURSIVE ) ); - - CPDFileFilter[] choices = getCPDFileFilters(); - JComboBox fileTypeSelector = new JComboBox( choices ); - fileTypeSelector.setSelectedIndex( lastSelectedFilter ); - fileTypeSelector.setEditable( false ); - - JTextField inclusionsRegex = new JTextField(); - inclusionsRegex.setText( lastInclusion ); - JTextField exclusionsRegex = new JTextField(); - exclusionsRegex.setText( lastExclusion ); - - pnlAccessory.add( lblMinTileSize, "0, 0, 1, 1, W,, 3" ); - pnlAccessory.add( txttilesize, "1, 0, 1, 1, W,, 3" ); - pnlAccessory.add( chkRecursive, "0, 1, 2, 1, W,, 3" ); - pnlAccessory.add( fileTypeSelector, "0, 2, 2, 1, W,, 3" ); - pnlAccessory.add( new JLabel( jEdit.getProperty( "net.sf.pmd.Inclusions", "Inclusions" ) ), "0, 3, 1, 1, W,, 3" ); - pnlAccessory.add( inclusionsRegex, "1, 3, 1, 1, W, w, 3" ); - pnlAccessory.add( new JLabel( jEdit.getProperty( "net.sf.pmd.Exclusions", "Exclusions" ) ), "0, 4, 1, 1, W,, 3" ); - pnlAccessory.add( exclusionsRegex, "1, 4, 1, 1, W, w, 3" ); - - chooser.setAccessory( pnlAccessory ); - - int returnVal = chooser.showOpenDialog( view ); - File selectedFile = null; - String inclusions = null; - String exclusions = null; - CPDFileFilter mode = null; - - if ( returnVal == JFileChooser.APPROVE_OPTION ) { - selectedFile = chooser.getSelectedFile(); - inclusions = inclusionsRegex.getText(); - jEdit.setProperty( LAST_INCLUSION_REGEX, inclusions ); - lastInclusion = inclusions; - exclusions = exclusionsRegex.getText(); - jEdit.setProperty( LAST_EXCLUSION_REGEX, exclusions ); - lastExclusion = exclusions; - mode = ( CPDFileFilter ) fileTypeSelector.getSelectedItem(); - lastSelectedFilter = fileTypeSelector.getSelectedIndex(); - jEdit.setIntegerProperty( LAST_SELECTED_FILTER, lastSelectedFilter ); - mode.setInclusions( inclusions ); - mode.setExclusions( exclusions ); - - if ( ! selectedFile.isDirectory() ) { - JOptionPane.showMessageDialog( view, jEdit.getProperty( "net.sf.pmd.Selection_not_a_directory.", "Selection not a directory." ), NAME, JOptionPane.ERROR_MESSAGE ); - return; - } - - int tilesize = 100; - try { - tilesize = Integer.parseInt( txttilesize.getText() ); - } catch ( NumberFormatException e ) { - // use the default. - tilesize = jEdit.getIntegerProperty( DEFAULT_TILE_MINSIZE_PROPERTY, 100 ); - } - - try { - jEdit.setBooleanProperty( CHECK_DIR_RECURSIVE, chkRecursive.isSelected() ); - instance.instanceCPDDir( view, selectedFile.getCanonicalPath(), tilesize, chkRecursive.isSelected(), mode ); - } catch ( IOException e ) { - Log.log( Log.ERROR, instance, "PMD ERROR: Unable to open file " + selectedFile, e ); - } - } - } - - /** - * Run CPD on a directory selected from the File System Browser. - * @param view The current view. - * @param browser The file system browser supplying the user selecte directory to check. - * @param recursive If true, check all files in the selected directory and all child - * directories, otherwise, just check the files in the selected directory only. - */ - public static void cpdDir( View view, VFSBrowser browser, boolean recursive ) throws IOException { - if ( view != null && browser != null ) { - VFSFile selectedDir[] = browser.getSelectedFiles(); - if ( selectedDir == null || selectedDir.length == 0 ) { - JOptionPane.showMessageDialog( view, jEdit.getProperty( "net.sf.pmd.One_Directory_has_to_be_selected_in_which_to_detect_duplicate_code.", "One Directory has to be selected in which to detect duplicate code." ), NAME, JOptionPane.ERROR_MESSAGE ); - return; - } - - if ( selectedDir[0].getType() != VFSFile.DIRECTORY ) { - JOptionPane.showMessageDialog( view, jEdit.getProperty( "net.sf.pmd.Selected_file_must_be_a_Directory.", "Selected file must be a Directory." ), NAME, JOptionPane.ERROR_MESSAGE ); - return; - } - - // display chooser for type of files to check - CPDFileFilter[] choices = getCPDFileFilters(); - CPDFileFilter choice = ( CPDFileFilter ) JOptionPane.showInputDialog( view, jEdit.getProperty( "net.sf.pmd.Select_type_of_files_to_check>", "Select type of files to check:" ), jEdit.getProperty( "net.sf.pmd.CPD,_Select_File_Type", "CPD, Select File Type" ), JOptionPane.OK_CANCEL_OPTION, null, choices, choices[0] ); - if ( choice == null ) { - return; - } - - instance.instanceCPDDir( view, selectedDir[0].getPath(), jEdit.getIntegerProperty( DEFAULT_TILE_MINSIZE_PROPERTY, 100 ), recursive, choice ); - } - } - - private static CPDFileFilter[] getCPDFileFilters() { - List filters = new ArrayList (); - Mode[] modes = jEdit.getModes(); - for ( Mode mode : modes ) { - String filenameGlob = ( String ) mode.getProperty( "filenameGlob" ); - if ( filenameGlob == null ) { - continue; - } - String modeName = mode.getName(); - filenameGlob = filenameGlob.replaceAll( "[*.{}\\[\\]]", "" ); - String[] extensions = filenameGlob.split( "[,]" ); - filters.add( new CPDFileFilter( modeName, modeName, extensions ) ); - } - Collections.sort( filters ); - return filters.toArray( new CPDFileFilter[filters.size()] ); - } - - private void instanceCPDDir( final View view, final String dir, final int tileSize, final boolean recursive, final CPDFileFilter mode ) { - if ( dir != null ) { - SwingWorker worker = new SwingWorker() { - @Override - public CPD doInBackground() { - jEdit.setProperty( LAST_DIRECTORY, dir ); - DefaultErrorSource errorSource = getErrorSource( view ); - errorSource.clear(); - CPD cpd = getCPD( tileSize, mode ); - - try { - if ( recursive ) { - cpd.addRecursively( dir ); - } else { - cpd.addAllInDirectory( dir ); - } - cpd.go(); - return cpd; - } catch ( Exception e ) { - Log.log( Log.ERROR, this, "Unable to run CPD: " + e.getMessage() ); - return null; - } - } - - @Override - public void done() { - try { - CPD cpd = get(); - if ( cpd == null ) { - view.getStatus().setMessageAndClear( jEdit.getProperty( "net.sf.pmd.Cannot_run_CPD_on_Invalid_directory/files.", "Cannot run CPD on Invalid directory/files." ) ); - return; - } - instance.processDuplicates( cpd, view ); - } catch ( Exception e ) { - Log.log( Log.ERROR, this, "CPD, nable to process duplicates: " + e.getMessage() ); - } - } - }; - worker.execute(); - } - } - - private void processDuplicates( CPD cpd, View view ) { - CPDDuplicateCodeViewer dv = getCPDDuplicateCodeViewer( view ); - - dv.clearDuplicates(); - Iterator matches = cpd.getMatches(); - - if ( matches.hasNext() ) { - while ( matches.hasNext() ) { - Match match = matches.next(); - CPDDuplicateCodeViewer.Duplicates duplicates = dv. new Duplicates( match.getLineCount() + " duplicate lines", match.getSourceCodeSlice() ); // NOPMD - for ( Iterator occurrences = match.iterator(); occurrences.hasNext(); ) { - TokenEntry mark = occurrences.next(); - int lastLine = mark.getBeginLine() + match.getLineCount(); - CPDDuplicateCodeViewer.Duplicate duplicate = dv. new Duplicate( mark.getTokenSrcID(), mark.getBeginLine(), lastLine ); // NOPMD - duplicates.addDuplicate( duplicate ); - } - dv.addDuplicates( duplicates ); - } - } else { - dv.getRoot().add( new DefaultMutableTreeNode( jEdit.getProperty( "net.sf.pmd.No_duplicates_found.", "No duplicates found." ), false ) ); - } - dv.refreshTree(); - dv.expandAll(); - } - - public CPDDuplicateCodeViewer getCPDDuplicateCodeViewer( View view ) { - view.getDockableWindowManager().showDockableWindow( "cpd-viewer" ); - return ( CPDDuplicateCodeViewer ) view.getDockableWindowManager().getDockableWindow( "cpd-viewer" ); - - } - - public static void checkFile( View view, VFSBrowser browser ) { - instance.checkFile( view, browser.getSelectedFiles() ); - } - - public void checkFile( View view, VFSFile de[] ) { - if ( view != null && de != null ) { - List files = new ArrayList (); - - for ( VFSFile file : de ) { - if ( file.getType() == VFSFile.FILE ) { - files.add( new File( file.getPath() ) ); - } - } - - process( files, view ); - } - } - - public static void checkDirectory( View view, VFSBrowser browser, boolean recursive ) { - VFSFile de[] = browser.getSelectedFiles(); - - if ( de == null || de.length == 0 || de[0].getType() != VFSFile.DIRECTORY ) { - JOptionPane.showMessageDialog( view, jEdit.getProperty( "net.sf.pmd.Selection_must_be_a_directory", "Selection must be a directory" ), NAME, JOptionPane.ERROR_MESSAGE ); - return; - } - - instance.process( instance.findFiles( de[0].getPath(), recursive ), view ); - } - - public void startProgressBarDisplay( final View view, final int max ) { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - instance.progressBar = getProgressWidget( view ); - if ( instance.progressBar != null ) { - instance.progressBar.setMaximum( max ); - } - } - } ); - } - - public void endProgressBarDisplay() { - if ( instance.progressBar != null ) { - int delay = 2000; - ActionListener timerTask = new ActionListener() { - public void actionPerformed( ActionEvent ae ) { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - instance.progressBar.complete(); - } - } ); - } - }; - javax.swing.Timer timer = new javax.swing.Timer(delay, timerTask); - timer.setRepeats(false); - timer.start(); - } - } - - private PMDProgressWidgetFactory.ProgressWidget getProgressWidget( View view ) { - PMDProgressWidgetFactory widgetFactory = ( PMDProgressWidgetFactory ) ServiceManager.getService( "org.gjt.sp.jedit.gui.statusbar.StatusWidgetFactory", "pmd" ); - if ( widgetFactory == null ) { - return null; - } - return ( PMDProgressWidgetFactory.ProgressWidget ) widgetFactory.getWidget( view ); - } - - /** - * Removes the PMD progress bar from all Views. - */ - public static void removeProgressBar() { - String statusBar = jEdit.getProperty("view.status"); - String[] widgets = statusBar.split("[ ]"); - StringBuilder sb = new StringBuilder(); - for (String widget : widgets) { - if ("pmd".equals(widget)) { - continue; - } - sb.append(widget).append(' '); - } - sb.deleteCharAt(sb.length() - 1); - jEdit.setProperty("view.status", sb.toString()); - } - - /** - * Adds the PMD progress bar to all views depending on the SHOW_PROGRESS property value. - */ - public static void addProgressBar() { - removeProgressBar(); - StringBuilder statusBar = new StringBuilder(jEdit.getProperty("view.status")); - boolean showProgressBar = jEdit.getBooleanProperty(PMDJEditPlugin.SHOW_PROGRESS, false); - if (showProgressBar) { - statusBar.append(" pmd"); - } - jEdit.setProperty("view.status", statusBar.toString()); - - } - - public void exportErrorAsReport( final View view, Report reports[] ) { - - String format = jEdit.getProperty( PMDJEditPlugin.RENDERER ); - - // "None", "Text", "Html", "XML", "CSV" - if ( format != null && ! format.equals( "None" ) ) { - net.sourceforge.pmd.renderers.Renderer renderer = null; - - if ( "XML".equals( format ) ) { - renderer = new XMLRenderer(); - } else { - if ( "Html".equals( format ) ) { - renderer = new HTMLRenderer(); - } else { - if ( "CSV".equals( format ) ) { - renderer = new CSVRenderer(); - } else { - if ( "Text".equals( format ) ) { - renderer = new TextRenderer(); - } else { - JOptionPane.showMessageDialog( view, jEdit.getProperty( "net.sf.pmd.Invalid_Renderer", "Invalid Renderer" ), NAME, JOptionPane.ERROR_MESSAGE ); - return; - } - } - } - } - - if ( reports != null ) { - final StringWriter sw = new StringWriter(); - final Writer writer = new BufferedWriter( sw ); - try { - renderer.setWriter( writer ); - renderer.start(); - for ( Report report : reports ) { - if ( report != null ) { - try { - renderer.renderFileReport( report ); // TODO: pmd throws an NPE here - } catch ( Exception e ) { // NOPMD - } - } - } - renderer.end(); - } catch ( IOException ioe ) { - Log.log( Log.ERROR, this, "Renderer can't report.", ioe ); - } finally { - try { - writer.close(); - } catch ( Exception ignored ) { // NOPMD - } - } - - final Buffer buffer = jEdit.newFile( view ); - view.setBuffer( buffer ); - SwingUtilities.invokeLater( new Runnable() { - public void run() { - buffer.writeLock(); - buffer.insert(0, sw.toString() ); - buffer.writeUnlock(); - } - } ); - } - } - } - - class ProgressBar extends JPanel { - private JProgressBar pBar; - private View view; - - public ProgressBar( View view, int min, int max ) { - super(); - this.view = view; - setLayout( new BorderLayout() ); - pBar = new JProgressBar( min, max ); - pBar.setBorder( new EtchedBorder( EtchedBorder.RAISED ) ); - pBar.setToolTipText( jEdit.getProperty( "net.sf.pmd.PMD_Check_in_Progress", "PMD Check in Progress" ) ); - pBar.setForeground( jEdit.getColorProperty( "pmd.progressbar.background" ) ); - pBar.setBackground( jEdit.getColorProperty( "view.status.background" ) ); - - pBar.setStringPainted( true ); - add( pBar, BorderLayout.CENTER ); - } - - public void increment( final int num ) { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - pBar.setValue( pBar.getValue() + num ); - } - } ); - } - - public void completeBar() { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - pBar.setValue( pBar.getMaximum() ); - view.getStatus().remove( pBar ); - } - } ); - } - } - - private CPD getCPD( int tileSize, final CPDFileFilter fileType ) { - Language lang = null; - LanguageFactory lf = new LanguageFactory(); - List supportedLanguages = Arrays.asList( LanguageFactory.supportedLanguages ); - - Properties props = new Properties(); - if ( "java".equals( fileType.getMode() ) ) { - props.setProperty( JavaTokenizer.IGNORE_LITERALS, String.valueOf( jEdit.getBooleanProperty( PMDJEditPlugin.IGNORE_LITERALS ) ) ); - } - if ( supportedLanguages.contains( fileType.getMode() ) ) { - lang = lf.createLanguage( fileType.getMode(), props ); - } else { - lang = new AnyLanguage( fileType.getExtensions() ) { - public FilenameFilter getFileFilter() { - return fileType; - } - }; - } - return lang == null ? null : new CPD( new CPDConfiguration( tileSize, lang, "UTF-8" ) ); - } - - private CPD getCPD( String fileType ) { - Mode mode = jEdit.getMode( fileType ); - if ( mode == null ) { - return null; - } - String filenameGlob = ( String ) mode.getProperty( "filenameGlob" ); - if ( filenameGlob == null ) { - return null; - } - filenameGlob = filenameGlob.replaceAll( "[*.{}]", "" ); - String[] extensions = filenameGlob.split( "[,]" ); - String modeName = mode.getName(); - CPDFileFilter filter = new CPDFileFilter( modeName, modeName, extensions ); - return getCPD( jEdit.getIntegerProperty( PMDJEditPlugin.DEFAULT_TILE_MINSIZE_PROPERTY, 100 ), filter ); - } - - /** - * Run the PMD rule designer. - */ - public static void runDesigner() { - String[] args = new String [] {"-noexitonclose"}; - new Designer( args ); - } -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDProgressWidgetFactory.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDProgressWidgetFactory.java deleted file mode 100644 index b839dca378..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDProgressWidgetFactory.java +++ /dev/null @@ -1,113 +0,0 @@ -package net.sourceforge.pmd.jedit; - -import org.gjt.sp.jedit.gui.statusbar.*; - -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.HashMap; -import javax.swing.JComponent; -import javax.swing.JProgressBar; -import javax.swing.SwingUtilities; - -import org.gjt.sp.jedit.View; - -/** - * A progress bar for PMD to display when processing multiple files. Increments - * the progress bar as each file is processed. - */ -public class PMDProgressWidgetFactory implements StatusWidgetFactory { - - HashMap cache = new HashMap(); - - public Widget getWidget( View view ) { - ProgressWidget widget = cache.get( view ); - if ( widget == null ) { - widget = new ProgressWidget(); - cache.put( view, widget ); - } - widget.setVisible( true ); - return widget; - } - - /** - * Sets the maximum value for the progress bar displayed for the given view. - * @param view The View displaying the progress bar. - * @param max The number of files to be processed. - */ - public void setBounds( View view, int max ) { - ProgressWidget widget = cache.get( view ); - if ( widget == null ) { - return; - } - widget.setMaximum( max ); - } - - public class ProgressWidget implements Widget, PropertyChangeListener { - - JProgressBar progressBar = null; - - public ProgressWidget() { - progressBar = new JProgressBar(0, 0 ); - progressBar.setValue(0 ); - progressBar.setString( "" ); - progressBar.setStringPainted( true ); - progressBar.setVisible(false); - } - - public JComponent getComponent() { - return progressBar; - } - - public void update() { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - progressBar.setValue( progressBar.getValue() + 1 ); - progressBar.setString( String.valueOf( ( int ) ( 100 * progressBar.getValue() / progressBar.getMaximum() ) ) + '%' ); - } - } ); - } - - /** - * Calls update. For use by a SwingWorker. - * @param event Not used. - */ - public void propertyChange( PropertyChangeEvent event ) { - update(); - } - - /** - * Not used. - */ - public void propertiesChanged() { - } - - public void setMaximum( int max ) { - progressBar.setMaximum( max ); - } - - public void complete() { - progressBar.setValue( progressBar.getMaximum() - 1 ); - update(); - - int delay = 2000; - ActionListener timerTask = new ActionListener() { - public void actionPerformed( ActionEvent ae ) { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - progressBar.setVisible( false ); - } - } ); - } - }; - javax.swing.Timer timer = new javax.swing.Timer( delay, timerTask ); - timer.setRepeats( false ); - timer.start(); - } - - public void setVisible( boolean visible ) { - progressBar.setVisible( visible ); - } - } -} diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDRulesOptionPane.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDRulesOptionPane.java deleted file mode 100644 index 4e9648f3d5..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDRulesOptionPane.java +++ /dev/null @@ -1,324 +0,0 @@ -/* -* User: tom -* Date: Jul 8, 2002 -* Time: 4:29:19 PM -*/ -package net.sourceforge.pmd.jedit; - -import net.sourceforge.pmd.jedit.checkboxtree.*; - -import org.gjt.sp.jedit.AbstractOptionPane; -import org.gjt.sp.jedit.OptionPane; -import org.gjt.sp.jedit.jEdit; -import org.gjt.sp.jedit.GUIUtilities; -import org.gjt.sp.util.StringList; -import org.gjt.sp.jedit.browser.VFSBrowser; -import org.gjt.sp.jedit.browser.VFSFileChooserDialog; - -import java.awt.FlowLayout; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.filechooser.FileFilter; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreePath; -import java.util.List; -import java.awt.Dimension; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleSet; -import net.sourceforge.pmd.RuleSets; -import net.sourceforge.pmd.RuleSetWriter; -import java.io.*; - -import common.gui.pathbuilder.PathBuilder; -import common.gui.pathbuilder.PathBuilderDialog; -import ise.java.awt.KappaLayout; - -/* - TODO: put strings in properties file - QUESTION: would it be possible to run the examples through the Beauty plugin - and the Code2Html plugin to format and colorize the examples per the users preferences? - DONE: make custom rules a separate panel. -- added custom rules dialog. - DONE: add ability to export current ruleset. -*/ -public class PMDRulesOptionPane extends AbstractOptionPane implements OptionPane { - - SelectedRules rules; - - JTextArea exampleTextArea = new JTextArea( 12, 60 ); - JTextField txtCustomRules; - CheckboxTree tree; - JCheckBox useDefaultRules; - JLabel exampleLabel; - JButton exportButton; - JButton customRulesButton; - - - static final String USE_DEFAULT_RULES_KEY = "pmd.use-default-rules"; - - - public PMDRulesOptionPane() { - super( PMDJEditPlugin.NAME ); - rules = new SelectedRules(); - } - - public void _init() { - removeAll(); - setLayout(new FlowLayout(FlowLayout.LEFT)); - - JPanel panel = new JPanel(new KappaLayout()); - panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); - - JLabel title = new JLabel("" + jEdit.getProperty("options.pmd.rules.label", "PMD Rules")); - - panel.add("0, 0, 1, 1, W, w, 3", title); - panel.add("0, 1, 1, 1, W, w, 3", getRulesPanel()); - - add(panel); - } - - private JPanel getRulesPanel() { - JPanel panel = new JPanel(); - panel.setLayout( new KappaLayout() ); - - JLabel rules_label = new JLabel( jEdit.getProperty( "net.sf.pmd.Rules", "Rules" ) ); - useDefaultRules = new JCheckBox( jEdit.getProperty( "net.sf.pmd.Select_default_rules", "Select default rules" ) ); - useDefaultRules.setSelected( jEdit.getBooleanProperty( USE_DEFAULT_RULES_KEY, false ) ); - - // use a checkbox tree for displaying the rules. This lets the rules be - // grouped by ruleset, and makes it very easy to select an entire set of - // rules with a single click. The tree is only 2 levels - // deep, the first level is the ruleset level, the second level contains the - // individual rules. Using the PROPAGATE_PRESERVING_UNCHECK checking mode - // means the ruleset will be checked if one or more of the rules it contains - // is checked. - JScrollPane rules_pane = null; - if ( rules == null ) { - JOptionPane.showMessageDialog( null, - jEdit.getProperty( "net.sf.pmd.Error_loading_rules._Check_any_custom_rulesets_for_errors.", "Error loading rules. Check any custom rulesets for errors." ), - jEdit.getProperty( "net.sf.pmd.Error_Loading_Rules", "Error Loading Rules" ), - JOptionPane.ERROR_MESSAGE ); - } - else { - if ( jEdit.getBooleanProperty( USE_DEFAULT_RULES_KEY, false ) ) { - rules.loadGoodRulesTree(); - } - tree = new CheckboxTree( rules.getRoot() ); - tree.getCheckingModel().setCheckingMode( TreeCheckingModel.CheckingMode.PROPAGATE_PRESERVING_UNCHECK ); - tree.setCheckingPaths( rules.getCheckingModel().getCheckingPaths() ); - tree.setRootVisible( false ); - tree.addMouseMotionListener( new MyMouseMotionAdapter() ); - rules_pane = new JScrollPane( tree ); - rules_pane.setMaximumSize( new Dimension( 500, 200 ) ); - rules_pane.setPreferredSize( new Dimension( 500, 200 ) ); - } - - useDefaultRules.addActionListener( - new ActionListener() { - public void actionPerformed( final ActionEvent ae ) { - SwingUtilities.invokeLater( new Runnable() { - public void run() { - if ( ( ( JCheckBox ) ae.getSource() ).isSelected() ) { - rules.loadGoodRulesTree(); - customRulesButton.setEnabled( false ); - } - else { - rules.loadTree(); - customRulesButton.setEnabled( true ); - } - tree.setModel( rules.getTreeModel() ); - tree.getCheckingModel().setCheckingMode( TreeCheckingModel.CheckingMode.PROPAGATE_PRESERVING_UNCHECK ); - tree.setCheckingPaths( rules.getCheckingModel().getCheckingPaths() ); - tree.invalidate(); - tree.validate(); - } - } - ); - } - } - ); - - exampleLabel = new JLabel( jEdit.getProperty( "net.sf.pmd.Example", "Example" ) ); - JScrollPane example_pane = new JScrollPane( exampleTextArea ); - example_pane.setMaximumSize( new Dimension( 500, 200 ) ); - example_pane.setPreferredSize( new Dimension( 500, 200 ) ); - - exportButton = new JButton( "Export this ruleset" ); - exportButton.addActionListener( - new ActionListener() { - public void actionPerformed( ActionEvent ae ) { - RuleSets rulesets = rules.getSelectedRules(); - RuleSet ruleset = new RuleSet(); - for ( RuleSet rs : rulesets.getAllRuleSets() ) { - ruleset.addRuleSet( rs ); - } - - // file chooser - VFSFileChooserDialog chooser = new VFSFileChooserDialog( GUIUtilities.getParentDialog( PMDRulesOptionPane.this ), - jEdit.getActiveView(), - System.getProperty( "user.home" ) + "/ruleset.xml", - VFSBrowser.SAVE_DIALOG, - false, - false ); - - chooser.setTitle( "Export Ruleset" ); - chooser.setVisible( true ); - - if ( chooser.getSelectedFiles() != null ) { - try { - String outfile = chooser.getSelectedFiles() [ 0 ]; - OutputStream outputStream = new BufferedOutputStream( new FileOutputStream( outfile ) ); - RuleSetWriter writer = new RuleSetWriter( outputStream ); - writer.write( ruleset ); - writer.close(); - } - catch ( Exception e ) { - JOptionPane.showMessageDialog( GUIUtilities.getParentDialog( PMDRulesOptionPane.this ), "Error saving ruleset:\n" + e.getMessage(), "Error Saving Ruleset", JOptionPane.ERROR_MESSAGE ); - } - } - } - } - ); - - - JLabel more_info_label = new JLabel( jEdit.getProperty( "net.sf.pmd.Please_see_http>//pmd.sf.net/_for_more_information", "Please see http://pmd.sf.net/ for more information" ) ); - - customRulesButton = new JButton( "Custom Rules" ); - customRulesButton.addActionListener( - new ActionListener() { - public void actionPerformed( ActionEvent ae ) { - customRulesDialog(); - } - } - ); - - panel.setBorder( BorderFactory.createEmptyBorder( 12, 11, 11, 12 ) ); - panel.add( "0, 0, 2, 1, W, w, 3", rules_label ); - panel.add( "0, 1, 2, 1, W, w, 3", useDefaultRules ); - panel.add( "0, 2, 2, 10, 0, w, 3", rules_pane ); - panel.add( "0, 12, 1, 1, 0, w, 3", exportButton ); - panel.add( "1, 12, 1, 1, 0, w, 3", customRulesButton ); - panel.add( "0, 13, 2, 1, W, w, 3", exampleLabel ); - panel.add( "0, 14, 2, 6, 0, wh, 3", example_pane ); - panel.add( "0, 20, 2, 1, W, w, 3", more_info_label ); - return panel; - } - - public void _save() { - if ( rules != null ) { - rules.save( tree.getCheckingModel() ); - } - - if ( txtCustomRules != null ) { - jEdit.setProperty( PMDJEditPlugin.CUSTOM_RULES_PATH_KEY, txtCustomRules - .getText() ); - } - jEdit.setBooleanProperty( USE_DEFAULT_RULES_KEY, useDefaultRules.isSelected() ); - } - - private class MyMouseMotionAdapter extends java.awt.event.MouseMotionAdapter { - public void mouseMoved( MouseEvent event ) { - TreePath path = tree.getPathForLocation( event.getX(), event.getY() ); - if ( path != null ) { - DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) path.getLastPathComponent(); - if ( node != null ) { - Object userObject = node.getUserObject(); - if ( userObject instanceof RuleNode ) { - changeExampleLabel( jEdit.getProperty( "net.sf.pmd.Example", "Example" ) ); - Rule rule = (( RuleNode ) userObject).getRule(); - String header = getRuleExampleHeader(rule); - List examples = ( ( RuleNode ) userObject ).getRule().getExamples(); - exampleTextArea.setLineWrap( true ); - exampleTextArea.setWrapStyleWord( true ); - exampleTextArea.setText( header + StringList.join( examples, "\n---------\n" ) ); - exampleTextArea.setCaretPosition( 0 ); - } - else if ( userObject instanceof RuleSetNode ) { - changeExampleLabel( jEdit.getProperty( "net.sf.pmd.Description", "Description" ) ); - String description = ( ( RuleSetNode ) userObject ).getRuleSet().getDescription(); - description = cleanUpDescription( description ); - exampleTextArea.setLineWrap( true ); - exampleTextArea.setWrapStyleWord( true ); - exampleTextArea.setText( description ); - exampleTextArea.setCaretPosition( 0 ); - } - } - } - } - } - - private String getRuleExampleHeader( Rule rule ) { - StringBuilder sb = new StringBuilder(128); - sb.append("Name: " ).append(rule.getName()); - sb.append("\nLanguage: ").append(rule.getLanguage().getName()); - sb.append("\nDescription: ").append(cleanUpDescription(rule.getDescription())); - sb.append("\nError Message: ").append(rule.getMessage()); - sb.append("\nPriority: ").append(rule.getPriority().toString()).append('\n'); - return sb.toString(); - } - - private String cleanUpDescription( String desc ) { - desc = desc.replaceAll( "\\s+", " " ); - desc = desc.trim(); - return desc; - } - - private void changeExampleLabel( final String text ) { - SwingUtilities.invokeLater( - new Runnable() { - public void run() { - exampleLabel.setText( text ); - exampleLabel.repaint(); - } - } - ); - } - - private void customRulesDialog() { - PathBuilderDialog dialog = new PathBuilderDialog( jEdit.getActiveView(), "Choose Custom Rulesets", "Custom Ruleset Files" ); - PathBuilder pathBuilder = dialog.getPathBuilder(); - pathBuilder.setAddButtonText( "Add Ruleset" ); - pathBuilder.setRemoveButtonText( "Remove Ruleset" ); - pathBuilder.setFileDialogTitle( "Select Ruleset File" ); - pathBuilder.setFileFilter( new RulesetFileFilter() ); - String paths = jEdit.getProperty( PMDJEditPlugin.CUSTOM_RULES_PATH_KEY, "" ); - paths = paths.replaceAll( ",", File.pathSeparator ); - pathBuilder.setPath( paths ); - - dialog.setVisible( true ); - - if ( dialog.getResult() ) { - paths = pathBuilder.getPath(); - paths = paths.replaceAll( File.pathSeparator, "," ); - jEdit.setProperty( PMDJEditPlugin.CUSTOM_RULES_PATH_KEY, paths ); - - SwingUtilities.invokeLater( - new Runnable() { - public void run() { - try { - rules = new SelectedRules(); - tree.setModel( rules.getTreeModel() ); - tree.getCheckingModel().setCheckingMode( TreeCheckingModel.CheckingMode.PROPAGATE_PRESERVING_UNCHECK ); - tree.setCheckingPaths( rules.getCheckingModel().getCheckingPaths() ); - tree.invalidate(); - tree.validate(); - tree.repaint(); - } - catch ( Exception e ) { - e.printStackTrace(); - } - } - } - ); - } - } - - public class RulesetFileFilter extends FileFilter { - public boolean accept( File f ) { - return f != null && ( f.isDirectory() || f.getName().endsWith( ".xml" ) ); - } - public String getDescription() { - return "PMD Ruleset Files"; - } - } -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/RuleCheckBox.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/RuleCheckBox.java deleted file mode 100644 index af62f50898..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/RuleCheckBox.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.sourceforge.pmd.jedit; - -import javax.swing.JCheckBox; - -import org.gjt.sp.jedit.jEdit; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleSet; - -@Deprecated -public class RuleCheckBox extends JCheckBox { - - private static final long serialVersionUID = 4779236734852745643L; - - private final Rule rule; - - private final RuleSet ruleset; - - public RuleCheckBox(Rule rule, RuleSet rs) { - super(rule.getName()); - this.rule = rule; - this.ruleset = rs; - - setSelected(jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_RULES_PREFIX + rule.getName(), true)); - } - - public String toString() { - return rule.getName(); - } - - /** - * @return the rule - */ - public Rule getRule() { - return rule; - } - - /** - * @return the ruleset - */ - public RuleSet getRuleset() { - return ruleset; - } - -} diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/RuleNode.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/RuleNode.java deleted file mode 100644 index 0edeaf15f0..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/RuleNode.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.sourceforge.pmd.jedit; - -import net.sourceforge.pmd.Rule; - -public class RuleNode { - - private Rule rule; - private final String name; - - public RuleNode( Rule rule ) { - this.rule = rule; - StringBuilder sb = new StringBuilder( rule.getName() ); - sb.append(" (").append(rule.getPriority().toString()).append(')'); - name = sb.toString(); - } - - public String toString() { - return name; - } - - public Rule getRule() { - return rule; - } -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/RuleSetNode.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/RuleSetNode.java deleted file mode 100644 index a478a9da05..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/RuleSetNode.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.sourceforge.pmd.jedit; - -import net.sourceforge.pmd.RuleSet; - -public class RuleSetNode { - - private RuleSet rule; - - public RuleSetNode(RuleSet rule) { - this.rule = rule; - } - - public String toString() { - return rule.getName(); - } - - public RuleSet getRuleSet() { - return rule; - } -} diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/SelectedRules.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/SelectedRules.java deleted file mode 100644 index f06b726ffe..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/SelectedRules.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * User: tom - * Date: Jul 9, 2002 - * Time: 1:18:38 PM -*/ -package net.sourceforge.pmd.jedit; - -import java.io.File; -import java.util.*; - -import javax.swing.JOptionPane; -import javax.swing.tree.*; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleSet; -import net.sourceforge.pmd.RuleSetFactory; -import net.sourceforge.pmd.RuleSetNotFoundException; -import net.sourceforge.pmd.RuleSets; - -import net.sourceforge.pmd.jedit.checkboxtree.*; - -import org.gjt.sp.jedit.jEdit; - -/** - * Description of the Class - * - * @author jiger.p - * @created April 22, 2003 - */ -public class SelectedRules { - - // root of tree to show rule sets and rules - private DefaultMutableTreeNode root = new DefaultMutableTreeNode(); - - // model for the checkbox tree - private TreeModel treeModel = null; - - // model of the checkboxes for the tree that shows the rule sets and rules - private TreeCheckingModel checkingModel = null; - - // collection of rulesets built into PMD, this only needs loaded once - private List pmdRulesets = null; - - // set of java rules selected in the checking tree - private RuleSets selectedRules = null; - - - /** - * Loads PMD standard rulesets and any user defined custom rulesets, creates - * a checkbox tree model and root tree node for the rules. - */ - public SelectedRules() { - loadRuleSets(); - loadTree(); - } - - public void loadRuleSets() { - List rulesets = new ArrayList (); - - // load the rulesets built into PMD - if (pmdRulesets == null) { - pmdRulesets = loadPMDRuleSets(); - } - for (RuleSet ruleset : pmdRulesets) { - rulesets.add(ruleset); - } - - // load any custom rulesets - List custom_rulesets = loadCustomRuleSets(); - for (RuleSet ruleset : custom_rulesets) { - rulesets.add(ruleset); - } - - // sort the rulesets and add the individual rules - Collections.sort(rulesets, rulesetSorter); - for (RuleSet rs : rulesets) { - addRuleSet2Rules(rs, root); - } - - } - - private List loadPMDRuleSets() { - List rulesets = new ArrayList (); - - try { - RuleSetFactory rsf = new RuleSetFactory(); - Iterator registered = rsf.getRegisteredRuleSets(); - while (registered.hasNext()) { - RuleSet rs = registered.next(); - //System.out.println("Added RuleSet " + rs.getName() + " description "+ rs.getDescription()); - rulesets.add(rs); - } - } catch (Exception e) { - e.printStackTrace(); - // QUESTION: rethrow? - } - return rulesets; - } - - private List loadCustomRuleSets() { - List rulesets = new ArrayList (); - // Load custom RuleSets if any, but do not die if there is any problem - // loading a custom ruleset. - try { - String customRuleSetPath = jEdit.getProperty("pmd.customRulesPath"); - if (customRuleSetPath != null) { - File path = new File(customRuleSetPath); - if (!path.exists()) { - return rulesets; - } - RuleSetFactory rsf = new RuleSetFactory(); - RuleSets ruleSets = rsf.createRuleSets(customRuleSetPath); - if (ruleSets.getAllRuleSets() != null) { - for (RuleSet rs : ruleSets.getAllRuleSets()) { - rulesets.add(rs); - } - } - } - } catch (RuleSetNotFoundException e) { - JOptionPane.showMessageDialog(null, jEdit.getProperty("net.sf.pmd.There_was_an_error_loading_one_or_more_custom_rulesets,_so_no_custom_rulesets_were_loaded", "There was an error loading one or more custom rulesets, so no custom rulesets were loaded"), jEdit.getProperty("net.sf.pmd.Error_Loading_Custom_Ruleset", "Error Loading Custom Ruleset"), JOptionPane.ERROR_MESSAGE); - } - return rulesets; - } - - protected void loadGoodRulesTree() { - - Properties goodRules = new Properties(); - try { - goodRules.load(getClass().getClassLoader().getResourceAsStream("default_rules.props")); - } catch (Exception e) { - e.printStackTrace(); - } - - treeModel = new DefaultTreeModel(root); - checkingModel = new DefaultTreeCheckingModel(treeModel); - selectedRules = new RuleSets(); - - // load the selected rules from a list of good rules, this - // builds the checking model for the tree as well as the RuleSets for the - // selected rules to pass to PMD. - for (int i = 0; i < root.getChildCount(); i++) { - DefaultMutableTreeNode ruleSetNode = (DefaultMutableTreeNode) root.getChildAt(i); - RuleSet ruleset = new RuleSet(); - boolean hadCheckedRule = false; - for (int j = 0; j < ruleSetNode.getChildCount(); j++) { - DefaultMutableTreeNode ruleNode = (DefaultMutableTreeNode) ruleSetNode.getChildAt(j); - TreePath path = new TreePath(ruleNode.getPath()); - RuleNode rn = (RuleNode) ruleNode.getUserObject(); - String goodRuleChecked = goodRules.getProperty(PMDJEditPlugin.OPTION_RULES_PREFIX + rn.getRule().getName()); - boolean checked = goodRuleChecked == null ? false : "true".equals(goodRuleChecked); - if (checked) { - checkingModel.addCheckingPath(path); - ruleset.addRule(rn.getRule()); - hadCheckedRule = true; - } - } - if (hadCheckedRule) { - selectedRules.addRuleSet(ruleset); - } - } - } - - protected void loadTree() { - treeModel = new DefaultTreeModel(root); - checkingModel = new DefaultTreeCheckingModel(treeModel); - selectedRules = new RuleSets(); - - // load the previously saved and selected rules from jEdit properties, this - // builds the checking model for the tree as well as the RuleSets for the - // selected rules to pass to PMD. - for (int i = 0; i < root.getChildCount(); i++) { - DefaultMutableTreeNode ruleSetNode = (DefaultMutableTreeNode) root.getChildAt(i); - RuleSet ruleset = new RuleSet(); - ruleset.setName("java"); - boolean hadCheckedRule = false; - for (int j = 0; j < ruleSetNode.getChildCount(); j++) { - DefaultMutableTreeNode ruleNode = (DefaultMutableTreeNode) ruleSetNode.getChildAt(j); - TreePath path = new TreePath(ruleNode.getPath()); - RuleNode rn = (RuleNode) ruleNode.getUserObject(); - boolean checked = jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_RULES_PREFIX + rn.getRule().getName(), false); - if (checked) { - checkingModel.addCheckingPath(path); - ruleset.addRule(rn.getRule()); - hadCheckedRule = true; - } - } - if (hadCheckedRule) { - selectedRules.addRuleSet(ruleset); - } - } - } - - public TreeModel getTreeModel() { - return treeModel; - } - - public TreeCheckingModel getCheckingModel() { - return checkingModel; - } - - // save the rules selected by the user in the options pane. - public void save(TreeCheckingModel tcm) { - checkingModel = tcm; - root = (DefaultMutableTreeNode) checkingModel.getTreeModel().getRoot(); - - for (int i = 0; i < root.getChildCount(); i++) { - DefaultMutableTreeNode ruleSetNode = (DefaultMutableTreeNode) root.getChildAt(i); - for (int j = 0; j < ruleSetNode.getChildCount(); j++) { - DefaultMutableTreeNode ruleNode = (DefaultMutableTreeNode) ruleSetNode.getChildAt(j); - TreePath path = new TreePath(ruleNode.getPath()); - boolean checked = checkingModel.isPathChecked(path); - RuleNode rn = (RuleNode) ruleNode.getUserObject(); - jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_RULES_PREFIX + rn.getRule().getName(), checked); - } - } - } - - /** - * Gets the selectedRules attribute of the SelectedRules object - * - * @return The selectedRules value - */ - public RuleSets getSelectedRules() { - return selectedRules; - } - - public RuleSets getCombinedRules() { - return selectedRules; - } - - /** - * Adds a feature to the RuleSet2Rules attribute of the SelectedRules object - * - * @param rs The feature to be added to the RuleSet2Rules attribute - */ - private void addRuleSet2Rules(RuleSet rs, DefaultMutableTreeNode rootNode) { - DefaultMutableTreeNode node = new DefaultMutableTreeNode(new RuleSetNode(rs)); - - List rules = new ArrayList (rs.getRules()); - Collections.sort(rules, ruleSorter); - - for (Rule rule : rules) { - DefaultMutableTreeNode ruleNode = new DefaultMutableTreeNode(new RuleNode(rule)); - node.add(ruleNode); - } - rootNode.add(node); - } - - public TreeNode getRoot() { - return root; - } - - private final Comparator ruleSorter = new Comparator () { - public int compare(Rule r1, Rule r2) { - if (r1 == null) { - return 1; - } - if (r2 == null) { - return -1; - } - return r1.getName().compareTo(r2.getName()); - } - } ; - - private final Comparator rulesetSorter = new Comparator () { - public int compare(RuleSet r1, RuleSet r2) { - if (r1 == null) { - return 1; - } - if (r2 == null) { - return -1; - } - return r1.getName().compareTo(r2.getName()); - } - } ; - -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/SelectedRulesRuleSetFactory.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/SelectedRulesRuleSetFactory.java deleted file mode 100644 index fd2732eec5..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/SelectedRulesRuleSetFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.sourceforge.pmd.jedit; - -import net.sourceforge.pmd.RuleSetFactory; -import net.sourceforge.pmd.RuleSets; - -/** - * A ruleset factory that only supplies the rules it is told about. - */ -public class SelectedRulesRuleSetFactory extends RuleSetFactory { - - RuleSets selectedRules = null; - - /** - * @param selectedRules The rule sets this factory knows about. It will only - * provide these rules and will not create any other rules. - */ - public SelectedRulesRuleSetFactory(RuleSets selectedRules) { - super(); - this.selectedRules = selectedRules; - } - - /** - * @param referenceString Not used. This factory only provides the rules it was - * given in the constructor. - */ - @Override - public RuleSets createRuleSets(String referenceString) { - return selectedRules; - } -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/CheckboxTree.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/CheckboxTree.java deleted file mode 100644 index f98019779b..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/CheckboxTree.java +++ /dev/null @@ -1,358 +0,0 @@ -/* -* Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of -* CheckboxTree. CheckboxTree is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or (at your -* option) any later version. CheckboxTree is distributed in the hope that it -* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -* Public License for more details. You should have received a copy of the GNU -* General Public License along with CheckboxTree; if not, write to the Free -* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA -*/ -package net.sourceforge.pmd.jedit.checkboxtree; - -import java.awt.Rectangle; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.JTree; -import javax.swing.tree.TreeCellRenderer; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; - -/** - * A tree whose nodes may be checked (e.g. the component usually found in - * software installers, that allows for selecting the features to - * install/uninstall). If a node has some child of different checking status is - * greyed. You can use the same constructors of Jtree to instantiate a new - * CheckboxTree Example from a TreeNode: - * - *
- * DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
- * root.add(new DefaultMutableTreeNode("child A"));
- * root.add(new DefaultMutableTreeNode("child B"));
- * CheckboxTree CheckboxTree = new CheckboxTree(root);
- * 
- * - * Example from a TreeModel: - * - *
- * DefaultTreeModel dtm = new DefaultTreeModel(root);
- *
- * CheckboxTree CheckboxTree = new CheckboxTree(root);
- * 
- * - * Default constructor (useful for gui builders): - * - *
- * CheckboxTree CheckboxTree = new CheckboxTree();
- * 
- * - * Then you can set the checking propagation style: - * - *
- * CheckboxTree.getCheckingModel().setCheckingMode(TreeCheckingModel.CheckingMode.SIMPLE);
- * CheckboxTree.getCheckingModel().setCheckingMode(TreeCheckingModel.CheckingMode.PROPAGATE);
- * CheckboxTree.getCheckingModel().setCheckingMode(TreeCheckingModel.CheckingMode.PROPAGATE_PRESERVING_CHECK);
- * CheckboxTree.getCheckingModel().setCheckingMode(TreeCheckingModel.CheckingMode.PROPAGATE_PRESERVING_UNCHECK);
- * 
- * - * You can also set the model at a later time using: - * - *
- * CheckboxTree.setModel(aTreeModel);
- * 
- * - * There are two methods that return the paths that are in the checking: - * - *
- * TreePath[] tp = CheckboxTree.getCheckingPaths();
- *
- * TreePath[] tp = CheckboxTree.getCheckingRoots();
- * 
- * - * You can also add/remove a listener of a TreeCheckingEvent in this way: - * - *
- * CheckboxTree.addTreeCheckingListener(new TreeCheckingListener() {
- *     public void valueChanged(TreeCheckingEvent e) {
- *  System.out.println("Checked paths changed: user clicked on " + (e.getLeadingPath().getLastPathComponent()));
- *     }
- * });
- * 
- * - * @author Enrico Boldrini - * @author Lorenzo Bigagli - */ - -public class CheckboxTree extends JTree { - - private TreeCheckingModel checkingModel; - - private class NodeCheckListener extends MouseAdapter { - @Override - public void mousePressed( MouseEvent e ) { - // we use mousePressed instead of mouseClicked for performance - int x = e.getX(); - int y = e.getY(); - int row = getRowForLocation( x, y ); - if ( row == -1 ) { - // click outside any node - return ; - } - Rectangle rect = getRowBounds( row ); - if ( rect == null ) { - // clic on an invalid node - return ; - } - if ( ( ( CheckboxTreeCellRenderer ) getCellRenderer() ).isOnHotspot( x - rect.x, y - rect.y ) ) { - getCheckingModel().toggleCheckingPath( getPathForRow( row ) ); - } - } - } - - /** - * For GUI builders. It returns a CheckboxTree with a default tree - * model to show something interesting. Creates a CheckboxTree with - * visible handles, a default CheckboxTreeCellRenderer and a default - * TreeCheckingModel. - */ - public CheckboxTree() { - super( getDefaultTreeModel() ); - initialize(); - } - - /** - * Creates a CheckboxTree with visible handles, a default - * CheckboxTreeCellRenderer and a default TreeCheckingModel. The tree is - * created using the specified data model. Mouse clicks are validated - * against the cell renderer (via isOnCheckBox) and, eventually, passed - * on to the checking model. - * - * @param root the root of the tree - */ - public CheckboxTree( TreeNode root ) { - super( root ); - initialize(); - } - - /** - * Creates a CheckboxTree with visible handles, a default - * CheckboxTreeCellRenderer and a default TreeCheckingModel. The tree is - * created using the specified data model. Mouse clicks are validated - * against the cell renderer (via isOnCheckBox) and, eventually, passed - * on to the checking model. - */ - public CheckboxTree( TreeModel treemodel ) { - super( treemodel ); - initialize(); - } - - - /** - * Convenience initialization method. - */ - private void initialize() { - setCheckingModel( new DefaultTreeCheckingModel( this.treeModel ) ); - DefaultCheckboxTreeCellRenderer cellRenderer = new DefaultCheckboxTreeCellRenderer(); - cellRenderer.setLeafIcon(null); /// danson, set these to null - cellRenderer.setClosedIcon(null); /// - cellRenderer.setOpenIcon(null); /// - setCellRenderer( cellRenderer ); - addMouseListener( new NodeCheckListener() ); - this.selectionModel.setSelectionMode( TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION ); - setShowsRootHandles( true ); - putClientProperty( "JTree.lineStyle", "Angled" ); // for Metal L&F - } - - /** - * Sets the CheckboxTreeCellRenderer that will be used to - * draw each cell. - * - * @param x the TreeCellRenderer that is to render each - * cell - * @beaninfo bound: true description: The TreeCellRenderer that will be - * used to draw each cell. - */ - public void setCellRenderer( CheckboxTreeCellRenderer x ) { - super.setCellRenderer( x ); - } - - /** - * Sets the TreeCellRenderer that will be used to draw - * each cell. This method is deprecated. Use the other setter for - * {@link CheckboxTreeCellRenderer} - * - * @param x the TreeCellRenderer that is to render each - * cell - * @beaninfo bound: true description: The TreeCellRenderer that will be - * used to draw each cell. - */ - @Override - @Deprecated - public void setCellRenderer( TreeCellRenderer x ) { - super.setCellRenderer( x ); - } - - /** - * Sets the TreeModel and links it to the existing checkingModel. - */ - @Override - public void setModel( TreeModel newModel ) { - super.setModel( newModel ); - if ( this.checkingModel != null ) { - this.checkingModel.setTreeModel( newModel ); - } - } - - /** - * @return Returns the TreeCheckingModel. - */ - public TreeCheckingModel getCheckingModel() { - return this.checkingModel; - } - - /** - * Set the checking model of this CheckboxTree. - * - * @param newCheckingModel The new TreeCheckingModel. - */ - public void setCheckingModel( TreeCheckingModel newCheckingModel ) { - /* - * we must unlink the old TreeCheckingModel from the model of this tree - * and link the new one to it. - */ - TreeCheckingModel oldCheckingModel = this.checkingModel; - if ( oldCheckingModel != null ) { - // null the model in the old TreeCheckingModel to avoid dangling - // pointers - oldCheckingModel.setTreeModel( null ); - } - // TODO: check newCheckingModel for == null and optionally substitute - // with EmptyCheckingModel... - this.checkingModel = newCheckingModel; - if ( newCheckingModel != null ) { - newCheckingModel.setTreeModel( getModel() ); - // add a treeCheckingListener to repaint upon checking - // modifications - newCheckingModel.addTreeCheckingListener( new TreeCheckingListener() { - public void valueChanged( TreeCheckingEvent e ) { - repaint(); - } - } - ); - } - } - - /** - * Return paths that are in the checking. - */ - public TreePath[] getCheckingPaths() { - return getCheckingModel().getCheckingPaths(); - } - - /** - * @return Returns the paths that are in the checking set and are the - * (upper) roots of checked trees. - */ - public TreePath[] getCheckingRoots() { - return getCheckingModel().getCheckingRoots(); - } - - /** - * Clears the checking. - */ - public void clearChecking() { - getCheckingModel().clearChecking(); - } - - /** - * Add paths in the checking. - */ - public void addCheckingPaths( TreePath[] paths ) { - getCheckingModel().addCheckingPaths( paths ); - } - - /** - * Add a path in the checking. - */ - public void addCheckingPath( TreePath path ) { - getCheckingModel().addCheckingPath( path ); - } - - /** - * Set path in the checking. - */ - public void setCheckingPath( TreePath path ) { - getCheckingModel().setCheckingPath( path ); - } - - /** - * Set paths that are in the checking. - */ - public void setCheckingPaths( TreePath[] paths ) { - getCheckingModel().setCheckingPaths( paths ); - } - - /** - * @return Returns the paths that are in the greying. - */ - public TreePath[] getGreyingPaths() { - return getCheckingModel().getGreyingPaths(); - } - - /** - * Adds a listener for TreeChecking events. - * - * @param tsl the TreeCheckingListener that will be - * notified when a node is checked - */ - public void addTreeCheckingListener( TreeCheckingListener tsl ) { - this.checkingModel.addTreeCheckingListener( tsl ); - } - - /** - * Removes a TreeChecking listener. - * - * @param tsl the TreeChckingListener to remove - */ - public void removeTreeCheckingListener( TreeCheckingListener tsl ) { - this.checkingModel.removeTreeCheckingListener( tsl ); - } - - /** - * Expand completely a tree - */ - public void expandAll() { - expandSubTree( getPathForRow( 0 ) ); - } - - private void expandSubTree( TreePath path ) { - expandPath( path ); - Object node = path.getLastPathComponent(); - int childrenNumber = getModel().getChildCount( node ); - TreePath[] childrenPath = new TreePath[ childrenNumber ]; - for ( int childIndex = 0; childIndex < childrenNumber; childIndex++ ) { - childrenPath[ childIndex ] = path.pathByAddingChild( getModel().getChild( node, childIndex ) ); - expandSubTree( childrenPath[ childIndex ] ); - } - } - - /** - * @return a string representation of the tree, including the checking, - * enabling and greying sets. - */ - @Override - public String toString() { - String retVal = super.toString(); - TreeCheckingModel tcm = getCheckingModel(); - if ( tcm != null ) { - return retVal + "\n" + tcm.toString(); - } - return retVal; - } -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/CheckboxTreeCellRenderer.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/CheckboxTreeCellRenderer.java deleted file mode 100644 index 194c96e8d6..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/CheckboxTreeCellRenderer.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import java.awt.Component; - -import javax.swing.JTree; -import javax.swing.tree.TreeCellRenderer; - -/** - * The renderer for a cell in a CheckboxTree. - * - * @author bigagli - */ -public interface CheckboxTreeCellRenderer extends TreeCellRenderer { - - /** - * This method is redeclared just to underline that the implementor has - * to properly display the checking/graying state of value. - * This should go in the method parameters, but would imply changes to - * Swing classes that were considered unpractical. For example in - * DefaultCheckboxTreeCellRenderer the following code is used to get the - * checking/graying states: - * - *
-         * TreeCheckingModel checkingModel = ((CheckboxTree) tree).getCheckingModel();
-         *
-         * TreePath path = tree.getPathForRow(row);
-         *
-         * boolean enabled = checkingModel.isPathEnabled(path);
-         *
-         * boolean checked = checkingModel.isPathChecked(path);
-         *
-         * boolean greyed = checkingModel.isPathGreyed(path);
-         * 
- * - * You could use a QuadristateCheckbox to properly renderer the states - * (as in DefaultCheckboxTreeCellRenderer). - * - * @see TreeCellRenderer#getTreeCellRendererComponent - */ - Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, - boolean hasFocus); - - /** - * Returns whether the specified relative coordinates insist on the - * intended checkbox control. May be used by a mouse listener to figure - * out whether to toggle a node or not. - */ - public boolean isOnHotspot(int x, int y); - -} diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/DefaultCheckboxTreeCellRenderer.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/DefaultCheckboxTreeCellRenderer.java deleted file mode 100644 index b18d9eb0c8..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/DefaultCheckboxTreeCellRenderer.java +++ /dev/null @@ -1,169 +0,0 @@ -/* -* Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of -* CheckboxTree. CheckboxTree is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or (at your -* option) any later version. CheckboxTree is distributed in the hope that it -* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -* Public License for more details. You should have received a copy of the GNU -* General Public License along with CheckboxTree; if not, write to the Free -* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA -*/ -package net.sourceforge.pmd.jedit.checkboxtree; - -import net.sourceforge.pmd.jedit.checkboxtree.QuadristateButtonModel.State; - -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; - -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.JPanel; -import javax.swing.JTree; -import javax.swing.UIManager; -import javax.swing.plaf.ColorUIResource; -import javax.swing.tree.DefaultTreeCellRenderer; -import javax.swing.tree.TreePath; - -/** - * A renderer for the CheckboxTree. This implementation decorates a - * DefaultTreeCellRenderer (i.e. a JLabel) with a checkbox, by adding a - * JCheckbox to the former onto a JPanel. Both can be overridden by subclasses. - * Note that this renderer separates the checkbox form the label/icon, in that - * double-clicking the label/icon of this renderer does not toggle the checkbox. - * - * @author boldrini - * @author bigagli - */ -public class DefaultCheckboxTreeCellRenderer extends JPanel implements CheckboxTreeCellRenderer { - - protected QuadristateCheckbox checkBox = new QuadristateCheckbox(); - - protected DefaultTreeCellRenderer label = new DefaultTreeCellRenderer(); - - public DefaultCheckboxTreeCellRenderer() { - this.setLayout( new FlowLayout( FlowLayout.LEFT, 0, 0 ) ); - add( this.checkBox ); - add( this.label ); - this.checkBox.setBackground( UIManager.getColor( "Tree.textBackground" ) ); - this.setBackground( UIManager.getColor( "Tree.textBackground" ) ); - } - - // @Override - // public void doLayout() { - // Dimension d_check = this.checkBox.getPreferredSize(); - // Dimension d_label = this.label.getPreferredSize(); - // int y_check = 0; - // int y_label = 0; - // if (d_check.height < d_label.height) { - // y_check = (d_label.height - d_check.height) / 2; - // } else { - // y_label = (d_check.height - d_label.height) / 2; - // } - // this.checkBox.setLocation(0, y_check); - // this.checkBox.setBounds(0, y_check, d_check.width, d_check.height); - // this.label.setLocation(d_check.width, y_label); - // this.label.setBounds(d_check.width, y_label, d_label.width, - // d_label.height); - // } - - @Override - public Dimension getPreferredSize() { - Dimension d_check = this.checkBox.getPreferredSize(); - Dimension d_label = this.label.getPreferredSize(); - return new Dimension( d_check.width + d_label.width, ( d_check.height < - d_label.height ? d_label.height : d_check.height ) ); - } - - /** - * Decorates this renderer based on the passed in components. - */ - public Component getTreeCellRendererComponent( JTree tree, Object object, boolean selected, boolean expanded, boolean leaf, int row, - boolean hasFocus ) { - /* - * most of the rendering is delegated to the wrapped - * DefaultTreeCellRenderer, the rest depends on the TreeCheckingModel - */ - this.label.getTreeCellRendererComponent( tree, object, selected, expanded, leaf, row, hasFocus ); - if ( tree instanceof CheckboxTree ) { - TreeCheckingModel checkingModel = ( ( CheckboxTree ) tree ).getCheckingModel(); - TreePath path = tree.getPathForRow( row ); - this.checkBox.setEnabled( checkingModel.isPathEnabled( path ) ); - boolean checked = checkingModel.isPathChecked( path ); - boolean greyed = checkingModel.isPathGreyed( path ); - if ( checked && !greyed ) { - this.checkBox.setState( State.CHECKED ); - } - if ( !checked && greyed ) { - this.checkBox.setState( State.GREY_UNCHECKED ); - } - if ( checked && greyed ) { - this.checkBox.setState( State.GREY_CHECKED ); - } - if ( !checked && !greyed ) { - this.checkBox.setState( State.UNCHECKED ); - } - } - return this; - } - - /** - * Checks if the (x,y) coordinates are on the Checkbox. - * - * @return boolean - * @param x - * @param y - */ - public boolean isOnHotspot( int x, int y ) { - // TODO: alternativa (ma funge???) - //return this.checkBox.contains(x, y); - return ( this.checkBox.getBounds().contains( x, y ) ); - } - - /** - * Loads an ImageIcon from the file iconFile, searching it in the - * classpath.Guarda un po' - */ - protected static ImageIcon loadIcon( String iconFile ) { - try { - return new ImageIcon( DefaultCheckboxTreeCellRenderer.class.getClassLoader().getResource( iconFile ) ); - } - catch ( NullPointerException npe ) { // did not find the resource - return null; - } - } - - @Override - public void setBackground( Color color ) { - if ( color instanceof ColorUIResource ) { - color = null; - } - super.setBackground( color ); - } - - /** - * Sets the icon used to represent non-leaf nodes that are expanded. - */ - public void setOpenIcon( Icon newIcon ) { - this.label.setOpenIcon( newIcon ); - } - - /** - * Sets the icon used to represent non-leaf nodes that are not expanded. - */ - public void setClosedIcon( Icon newIcon ) { - this.label.setClosedIcon( newIcon ); - } - - /** - * Sets the icon used to represent leaf nodes. - */ - public void setLeafIcon( Icon newIcon ) { - this.label.setLeafIcon( newIcon ); - } - -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/DefaultTreeCheckingModel.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/DefaultTreeCheckingModel.java deleted file mode 100644 index 36d40101cc..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/DefaultTreeCheckingModel.java +++ /dev/null @@ -1,719 +0,0 @@ -/* -* Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of -* CheckboxTree. CheckboxTree is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or (at your -* option) any later version. CheckboxTree is distributed in the hope that it -* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -* Public License for more details. You should have received a copy of the GNU -* General Public License along with CheckboxTree; if not, write to the Free -* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA -*/ -package net.sourceforge.pmd.jedit.checkboxtree; - -import java.util.HashSet; -import java.util.Vector; - -import javax.swing.event.EventListenerList; -import javax.swing.event.TreeModelEvent; -import javax.swing.event.TreeModelListener; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; - -/** - * The default tree checking model provides: - methods for store checked - * TreePaths and retrieve them. It doesn't provide the implementation of - * addCheckingPath and removeCheckingPath methods (are delegated to - * CheckingMode). This implementation is based on TreePath only and does not - * take advantage of TreeNode convenience methods. Alternative implementation - * may assume that the tree nodes be TreeNode instances. - * - * @author Bigagli - * @author Boldrini - */ -public class DefaultTreeCheckingModel implements TreeCheckingModel { - - private HashSet checkedPathsSet; - - private HashSet greyedPathsSet; - - private HashSet disabledPathsSet; - - private PropagateCheckingListener propagateCheckingListener; - - protected TreeCheckingMode checkingMode; - - protected TreeModel model; - - /** Event listener list. */ - protected EventListenerList listenerList = new EventListenerList(); - - /** - * Creates a DefaultTreeCheckingModel with PropagateTreeCheckingMode. - */ - public DefaultTreeCheckingModel( TreeModel model ) { - this.model = model; - this.checkedPathsSet = new HashSet(); - this.greyedPathsSet = new HashSet(); - this.disabledPathsSet = new HashSet(); - this.propagateCheckingListener = new PropagateCheckingListener(); - this.setCheckingMode( CheckingMode.PROPAGATE ); - } - - /** - * @deprecated - */ - @Deprecated - public TreeModelListener getTreeModelListener() { - return null; - } - - private class PropagateCheckingListener implements TreeModelListener { - /** - * Updates the check of the just inserted nodes. - */ - public void treeNodesInserted( TreeModelEvent e ) { - TreePath path = e.getTreePath(); - DefaultTreeCheckingModel.this.checkingMode.updateCheckAfterChildrenInserted( path ); - } - - /** - * Nothing to do if nodes were removed. - */ - public void treeNodesRemoved( TreeModelEvent e ) { - TreePath path = e.getTreePath(); - DefaultTreeCheckingModel.this.checkingMode.updateCheckAfterChildrenRemoved( path ); - } - - /** - * Updates the tree greyness in case of nodes changes. - */ - public void treeNodesChanged( TreeModelEvent e ) { - TreePath path = e.getTreePath(); - updateSubTreeGreyness( path ); - updateAncestorsGreyness( path ); - } - - /** - * Updates the tree greyness in case of structure changes. - */ - public void treeStructureChanged( TreeModelEvent e ) { - TreePath path = e.getTreePath(); - DefaultTreeCheckingModel.this.checkingMode.updateCheckAfterStructureChanged( path ); - } - } - - /** - * Updates consistency of the checking. It's based on paths greyness. - */ - public void updateCheckingConsistency() { - updateSubTreeCheckingConsistency( new TreePath( this.model.getRoot() ) ); - } - - /** - * Updates consistency of the checking of sub-tree starting at path. - * It's based on paths greyness. TODO: test this method, never used - * - * @param path the root of the sub-tree to be grey-updated - */ - public void updateSubTreeCheckingConsistency( TreePath path ) { - if ( isPathGreyed( path ) ) { - // greyed - for ( TreePath childPath : getChildrenPath( path ) ) { - updateSubTreeCheckingConsistency( childPath ); - } - updatePathGreyness( path ); - } - else { - // not greyed - if ( isPathChecked( path ) ) { - checkSubTree( path ); - } - else { - uncheckSubTree( path ); - } - return ; - } - } - - public boolean isPathChecked( TreePath path ) { - return this.checkedPathsSet.contains( path ); - } - - public boolean isPathEnabled( TreePath path ) { - return !this.disabledPathsSet.contains( path ); - } - - public boolean isPathGreyed( TreePath path ) { - return this.greyedPathsSet.contains( path ); - } - - void addToGreyedPathsSet( TreePath path ) { - this.greyedPathsSet.add( path ); - } - - void removeFromGreyedPathsSet( TreePath path ) { - this.greyedPathsSet.remove( path ); - } - - /** - * Sets whether or not the path is enabled. - * - * @param path the path to enable/disable - */ - public void setPathEnabled( TreePath path, boolean enable ) { - if ( enable ) { - this.disabledPathsSet.remove( path ); - } - else { - this.disabledPathsSet.add( path ); - } - } - - /** - * Sets whether or not the paths are enabled. - * - * @param paths the paths to enable/disable - */ - public void setPathsEnabled( TreePath[] paths, boolean enable ) { - for ( TreePath path : paths ) { - setPathEnabled( path, enable ); - } - } - - void addToCheckedPathsSet( TreePath path ) { - this.checkedPathsSet.add( path ); - } - - void removeFromCheckedPathsSet( TreePath path ) { - this.checkedPathsSet.remove( path ); - } - - /** - * Ungreys the subtree with root path. - * - * @param path root of the tree to be checked - */ - public void ungreySubTree( TreePath path ) { - removeFromGreyedPathsSet( path ); - for ( TreePath childPath : getChildrenPath( path ) ) { - ungreySubTree( childPath ); - } - } - - /** - * Checks the subtree with root path. - * - * @param path root of the tree to be checked - */ - public void checkSubTree( final TreePath path ) { - addToCheckedPathsSet( path ); - removeFromGreyedPathsSet( path ); - Object node = path.getLastPathComponent(); - int childrenNumber = this.model.getChildCount( node ); - for ( int childIndex = 0; childIndex < childrenNumber; childIndex++ ) { - TreePath childPath = path.pathByAddingChild( this.model.getChild( node, childIndex ) ); - checkSubTree( childPath ); - } - } - - /** - * Unchecks the subtree with root path. - * - * @param path root of the tree to be unchecked - */ - public void uncheckSubTree( TreePath path ) { - removeFromCheckedPathsSet( path ); - removeFromGreyedPathsSet( path ); - Object node = path.getLastPathComponent(); - int childrenNumber = this.model.getChildCount( node ); - for ( int childIndex = 0; childIndex < childrenNumber; childIndex++ ) { - TreePath childPath = path.pathByAddingChild( this.model.getChild( node, childIndex ) ); - uncheckSubTree( childPath ); - } - } - - /** - * Delegates to the current checkingMode the toggling style, using the - * Strategy Pattern. - */ - public void toggleCheckingPath( TreePath path ) { - if ( !isPathEnabled( path ) ) { - return ; - } - if ( isPathChecked( path ) ) { - removeCheckingPath( path ); - } - else { - addCheckingPath( path ); - } - - } - - /** - * Sets the checking to path. - */ - public void setCheckingPath( TreePath path ) { - clearChecking(); - addCheckingPath( path ); - } - - /** - * Sets the checking to paths. - */ - public void setCheckingPaths( TreePath[] paths ) { - clearChecking(); - for ( TreePath path : paths ) { - addCheckingPath( path ); - } - } - - /** - * Clears the checking. - */ - public void clearChecking() { - this.checkedPathsSet.clear(); - this.greyedPathsSet.clear(); - fireValueChanged( new TreeCheckingEvent( new TreePath( model.getRoot() ) ) ); - } - - /** - * @return The paths that are in the greying. - */ - public TreePath[] getGreyingPaths() { - return greyedPathsSet.toArray( new TreePath[ greyedPathsSet.size() ] ); - } - - /** - * @return Returns the paths that are in the checking. - */ - public TreePath[] getCheckingPaths() { - return checkedPathsSet.toArray( new TreePath[ checkedPathsSet.size() ] ); - } - - /** - * @return Returns the paths that are in the checking set and are the - * (upper) roots of checked trees. - */ - public TreePath[] getCheckingRoots() { - Vector roots = getCheckingRoots( new TreePath( this.model.getRoot() ) ); - return roots.toArray( new TreePath[] {} ); - } - - /** - * @param path - * @return - */ - private Vector getCheckingRoots( TreePath path ) { - Object node = path.getLastPathComponent(); - Vector roots = new Vector(); - if ( !isPathGreyed( path ) ) { - if ( isPathChecked( path ) ) { - roots.add( path ); - } - return roots; - } - // path is greyed - int childrenNumber = this.model.getChildCount( node ); - for ( int childIndex = 0; childIndex < childrenNumber; childIndex++ ) { - TreePath childPath = path.pathByAddingChild( this.model.getChild( node, childIndex ) ); - roots.addAll( getCheckingRoots( childPath ) ); - } - return roots; - } - - /** - * @return The CheckingMode. - */ - public CheckingMode getCheckingMode() { - if ( this.checkingMode instanceof SimpleTreeCheckingMode ) { - return CheckingMode.SIMPLE; - } - if ( this.checkingMode instanceof PropagateTreeCheckingMode ) { - return CheckingMode.PROPAGATE; - } - if ( this.checkingMode instanceof PropagatePreservingCheckTreeCheckingMode ) { - return CheckingMode.PROPAGATE_PRESERVING_CHECK; - } - if ( this.checkingMode instanceof PropagatePreservingUncheckTreeCheckingMode ) { - return CheckingMode.PROPAGATE_PRESERVING_UNCHECK; - } - if ( this.checkingMode instanceof PropagateUpWhiteTreeCheckingMode ) { - return CheckingMode.PROPAGATE_UP_UNCHECK; - } - return null; - } - - /** - * Sets the specified checking mode. The consistence of the existing - * checking is not enforced nor controlled. - */ - public void setCheckingMode( CheckingMode mode ) { - /* - * CheckingMode implements togglePath method. (Strategy Pattern was - * used). - */ - switch ( mode ) { - case SIMPLE: - this.checkingMode = new SimpleTreeCheckingMode( this ); - break; - case PROPAGATE: - this.checkingMode = new PropagateTreeCheckingMode( this ); - break; - case PROPAGATE_PRESERVING_CHECK: - this.checkingMode = new PropagatePreservingCheckTreeCheckingMode( this ); - break; - case PROPAGATE_PRESERVING_UNCHECK: - this.checkingMode = new PropagatePreservingUncheckTreeCheckingMode( this ); - break; - case PROPAGATE_UP_UNCHECK: - this.checkingMode = new PropagateUpWhiteTreeCheckingMode( this ); - break; - default: - break; - } - // // TODO: safe to delete??? - // updateTreeGreyness(); - } - - /** - * Sets the specified checking mode. The consistence of the existing - * checking is not enforced nor controlled. - */ - public void setCheckingMode( TreeCheckingMode mode ) { - this.checkingMode = mode; - } - - /** - * Adds the paths to the checked paths set - * - * @param paths the paths to be added. - */ - public void addCheckingPaths( TreePath[] paths ) { - for ( TreePath path : paths ) { - addCheckingPath( path ); - } - } - - /** - * Adds a path to the checked paths set - * - * @param path the path to be added. - */ - public void addCheckingPath( TreePath path ) { - this.checkingMode.checkPath( path ); - TreeCheckingEvent event = new TreeCheckingEvent( path ); - fireValueChanged( event ); - } - - /** - * Removes a path from the checked paths set - * - * @param path the path to be removed - */ - public void removeCheckingPath( TreePath path ) { - this.checkingMode.uncheckPath( path ); - TreeCheckingEvent event = new TreeCheckingEvent( path ); - fireValueChanged( event ); - } - - /** - * Removes the paths from the checked paths set - * - * @param paths the paths to be removed - */ - public void removeCheckingPaths( TreePath[] paths ) { - for ( TreePath path : paths ) { - removeCheckingPath( path ); - } - } - - /** - * Notifies all listeners that are registered for tree selection events - * on this object. - * - * @see #addTreeCheckingListener - * @see EventListenerList - */ - protected void fireValueChanged( TreeCheckingEvent e ) { - // Guaranteed to return a non-null array - Object[] listeners = this.listenerList.getListenerList(); - // Process the listeners last to first, notifying - // those that are interested in this event - for ( int i = listeners.length - 2; i >= 0; i -= 2 ) { - if ( listeners[ i ] == TreeCheckingListener.class ) { - ( ( TreeCheckingListener ) listeners[ i + 1 ] ).valueChanged( e ); - } - } - } - - /** - * Adds x to the list of listeners that are notified each time the set - * of checking TreePaths changes. - * - * @param x the new listener to be added - */ - public void addTreeCheckingListener( TreeCheckingListener x ) { - this.listenerList.add( TreeCheckingListener.class, x ); - } - - /** - * Removes x from the list of listeners that are notified each time the - * set of checking TreePaths changes. - * - * @param x the listener to remove - */ - public void removeTreeCheckingListener( TreeCheckingListener x ) { - this.listenerList.remove( TreeCheckingListener.class, x ); - } - - /** - * Updates the greyness value value for the given path if there are - * children with different values. Note: the greyness and cheking of - * children MUST BE consistent. - * - * @param ancestor the path to be grey-updated. - */ - protected void updatePathGreyness( TreePath ancestor ) { - boolean value = isPathChecked( ancestor ); - Object ancestorNode = ancestor.getLastPathComponent(); - int childrenNumber = this.model.getChildCount( ancestorNode ); - for ( int childIndex = 0; childIndex < childrenNumber; childIndex++ ) { - Object childNode = this.model.getChild( ancestorNode, childIndex ); - TreePath childPath = ancestor.pathByAddingChild( childNode ); - if ( isPathGreyed( childPath ) ) { - addToGreyedPathsSet( ancestor ); - return ; - } - if ( isPathChecked( childPath ) != value ) { - addToGreyedPathsSet( ancestor ); - return ; - } - } - removeFromGreyedPathsSet( ancestor ); - } - - /** - * Updates the greyness of sub-tree starting at path. - * - * @param path the root of the sub-tree to be grey-updated - */ - public void updateSubTreeGreyness( TreePath path ) { - if ( pathHasChildrenWithValue( path, !isPathChecked( path ) ) ) { - addToGreyedPathsSet( path ); - } - else { - removeFromGreyedPathsSet( path ); - } - if ( isPathGreyed( path ) ) { - for ( TreePath childPath : getChildrenPath( path ) ) { - updateSubTreeGreyness( childPath ); - } - return ; - } - else { - ungreySubTree( path ); - } - } - - /** - * Updates the greyness state of the entire tree. - */ - public void updateTreeGreyness() { - updateSubTreeGreyness( new TreePath( this.model.getRoot() ) ); - } - - public enum ChildrenChecking { - ALL_CHECKED, HALF_CHECKED, ALL_UNCHECKED, NO_CHILDREN - } - - public ChildrenChecking getChildrenChecking( TreePath path ) { - Object node = path.getLastPathComponent(); - int childrenNumber = this.model.getChildCount( node ); - boolean someChecked = false; - boolean someUnchecked = false; - for ( int childIndex = 0; childIndex < childrenNumber; childIndex++ ) { - TreePath childPath = path.pathByAddingChild( this.model.getChild( node, childIndex ) ); - if ( isPathGreyed( childPath ) ) { - return ChildrenChecking.HALF_CHECKED; - } - // not greyed - if ( isPathChecked( childPath ) ) { - if ( someUnchecked ) { - return ChildrenChecking.HALF_CHECKED; - } - someChecked = true; - } - else { - if ( someChecked ) { - return ChildrenChecking.HALF_CHECKED; - } - someUnchecked = true; - } - } - if ( someChecked ) { - return ChildrenChecking.ALL_CHECKED; - } - if ( someUnchecked ) { - return ChildrenChecking.ALL_UNCHECKED; - } - return ChildrenChecking.NO_CHILDREN; - } - - /** - * Note: The checking and the greyness of children MUST be consistent to - * work properly. - * - * @return true if exists an unchecked node in the subtree of path. - * @param path the root of the subtree to be checked. - */ - public boolean pathHasUncheckedChildren( TreePath path ) { - Object node = path.getLastPathComponent(); - int childrenNumber = this.model.getChildCount( node ); - for ( int childIndex = 0; childIndex < childrenNumber; childIndex++ ) { - TreePath childPath = path.pathByAddingChild( this.model.getChild( node, childIndex ) ); - if ( isPathGreyed( childPath ) | !isPathChecked( childPath ) ) { - return true; - } - } - return false; - } - - /** - * @return true if exists a checked node in the subtree of path. - * @param path the root of the subtree to be checked. - */ - public boolean pathHasCheckedChildren( TreePath path ) { - return pathHasChildrenWithValue( path, true ); - } - - /** - * @return true if exists a node with checked status value in the - * subtree of path. - * @param path the root of the subtree to be searched. - * @param value the value to be found. - */ - protected boolean pathHasChildrenWithValue( TreePath path, boolean value ) { - Object node = path.getLastPathComponent(); - int childrenNumber = this.model.getChildCount( node ); - for ( int childIndex = 0; childIndex < childrenNumber; childIndex++ ) { - TreePath childPath = path.pathByAddingChild( this.model.getChild( node, childIndex ) ); - if ( isPathChecked( childPath ) == value ) { - return true; - } - } - for ( int childIndex = 0; childIndex < childrenNumber; childIndex++ ) { - TreePath childPath = path.pathByAddingChild( this.model.getChild( node, childIndex ) ); - if ( pathHasChildrenWithValue( childPath, value ) ) { - return true; - } - } - return false; - } - - /** - * @return true if exists a child of node with a value different from - * itself. - * @param path the root path of the tree to be checked. - */ - public boolean hasDifferentChildren( TreePath path ) { - return pathHasChildrenWithValue( path, !isPathChecked( path ) ); - } - - /** - * Update the grayness value of the parents of path. Note: the greyness - * and checking of the other nodes (not ancestors) MUST BE consistent. - * - * @param path the treepath containing the ancestors to be grey-updated - */ - public void updateAncestorsGreyness( TreePath path ) { - TreePath[] parents = new TreePath[ path.getPathCount() ]; - parents[ 0 ] = path; - boolean greyAll = isPathGreyed( path ); - for ( int i = 1; i < parents.length; i++ ) { - parents[ i ] = parents[ i - 1 ].getParentPath(); - if ( greyAll ) { - addToGreyedPathsSet( parents[ i ] ); - } - else { - updatePathGreyness( parents[ i ] ); - greyAll = isPathGreyed( parents[ i ] ); - } - } - } - - /** - * Return the paths that are children of path, using methods of - * TreeModel. Nodes don't have to be of type TreeNode. - * - * @param path the parent path - * @return the array of children path - */ - protected TreePath[] getChildrenPath( TreePath path ) { - Object node = path.getLastPathComponent(); - int childrenNumber = this.model.getChildCount( node ); - TreePath[] childrenPath = new TreePath[ childrenNumber ]; - for ( int childIndex = 0; childIndex < childrenNumber; childIndex++ ) { - childrenPath[ childIndex ] = path.pathByAddingChild( this.model.getChild( node, childIndex ) ); - } - return childrenPath; - } - - public TreeModel getTreeModel() { - return this.model; - } - - /** - * Sets the specified tree model. The current cheking is cleared. - */ - public void setTreeModel( TreeModel newModel ) { - TreeModel oldModel = this.model; - if ( oldModel != null ) { - oldModel.removeTreeModelListener( this.propagateCheckingListener ); - } - this.model = newModel; - if ( newModel != null ) { - newModel.addTreeModelListener( this.propagateCheckingListener ); - } - clearChecking(); - } - - /** - * Return a string that describes the tree model including the values of - * checking, enabling, greying. - */ - @Override - public String toString() { - return toString( new TreePath( this.model.getRoot() ) ); - } - - /** - * Convenience method for getting a string that describes the tree - * starting at path. - * - * @param path the treepath root of the tree - */ - private String toString( TreePath path ) { - String checkString = "n"; - String greyString = "n"; - String enableString = "n"; - if ( isPathChecked( path ) ) { - checkString = "y"; - } - if ( isPathEnabled( path ) ) { - enableString = "y"; - } - if ( isPathGreyed( path ) ) { - greyString = "y"; - } - String description = "Path checked: " + checkString + " greyed: " + greyString + " enabled: " + enableString + " Name: " - + path.toString() + "\n"; - for ( TreePath childPath : getChildrenPath( path ) ) { - description += toString( childPath ); - } - return description; - } - -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagatePreservingCheckTreeCheckingMode.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagatePreservingCheckTreeCheckingMode.java deleted file mode 100644 index dc38cf6664..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagatePreservingCheckTreeCheckingMode.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import javax.swing.tree.TreePath; - -/** - * PropagatePreservingCheckTreeCheckingMode define a TreeCheckingMode with down - * and up recursion of the check when nodes are clicked. It propagates the change - * not only to descendants but also to ancestors. With regard to descendants - * this mode behaves exactly like the Propagate mode. With regard to ancestors - * it checks/unchecks them as needed so that a node is checked if and only if - * all of its children are checked. - * - * @author Boldrini - */ -public class PropagatePreservingCheckTreeCheckingMode extends TreeCheckingMode { - - PropagatePreservingCheckTreeCheckingMode(DefaultTreeCheckingModel model) { - super(model); - } - - @Override - public void checkPath(TreePath path) { - // check is propagated to children - this.model.checkSubTree(path); - // check all the ancestors with subtrees checked - TreePath[] parents = new TreePath[path.getPathCount()]; - parents[0] = path; - boolean uncheckAll = false; - boolean greyAll = false; - for (int i = 1; i < parents.length; i++) { - parents[i] = parents[i - 1].getParentPath(); - if (uncheckAll) { - this.model.removeFromCheckedPathsSet(parents[i]); - if (greyAll) { - this.model.addToGreyedPathsSet(parents[i]); - } else { - if (this.model.pathHasUncheckedChildren(parents[i])) { - this.model.addToGreyedPathsSet(parents[i]); - greyAll = true; - } else { - this.model.removeFromGreyedPathsSet(parents[i]); - } - } - } else { - switch (this.model.getChildrenChecking(parents[i])) { - case HALF_CHECKED: - this.model.removeFromCheckedPathsSet(parents[i]); - this.model.addToGreyedPathsSet(parents[i]); - uncheckAll = true; - greyAll = true; - break; - case ALL_UNCHECKED: - this.model.removeFromCheckedPathsSet(parents[i]); - this.model.removeFromGreyedPathsSet(parents[i]); - uncheckAll = true; - break; - case ALL_CHECKED: - this.model.addToCheckedPathsSet(parents[i]); - this.model.removeFromGreyedPathsSet(parents[i]); - break; - default: - case NO_CHILDREN: - System.err.println("This should not happen (PropagatePreservingCheckTreeCheckingMode)"); - break; - } - } - } - } - - @Override - public void uncheckPath(TreePath path) { - // uncheck is propagated to children - this.model.uncheckSubTree(path); - TreePath parentPath = path; - // uncheck is propagated to parents, too - while ((parentPath = parentPath.getParentPath()) != null) { - this.model.removeFromCheckedPathsSet(parentPath); - this.model.updatePathGreyness(parentPath); - } - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterChildrenInserted(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterChildrenInserted(TreePath parent) { - if (this.model.isPathChecked(parent)) { - checkPath(parent); - } else { - uncheckPath(parent); - } - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterChildrenRemoved(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterChildrenRemoved(TreePath parent) { - if (!this.model.isPathChecked(parent)) { - // System.out.println(parent +" was removed (not checked)"); - if (this.model.getChildrenPath(parent).length != 0) { - if (!this.model.pathHasChildrenWithValue(parent, false)) { - // System.out.println("uncheking it"); - checkPath(parent); - } - } - } - this.model.updatePathGreyness(parent); - this.model.updateAncestorsGreyness(parent); - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterStructureChanged(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterStructureChanged(TreePath parent) { - if (this.model.isPathChecked(parent)) { - checkPath(parent); - } else { - uncheckPath(parent); - } - } - -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagatePreservingUncheckTreeCheckingMode.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagatePreservingUncheckTreeCheckingMode.java deleted file mode 100644 index 90867aecf4..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagatePreservingUncheckTreeCheckingMode.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import javax.swing.tree.TreePath; - -/** - * PropagatePreservingUncheckTreeCheckingMode define a TreeCheckingMode with - * down and up recursion of the check when nodes are clicked. It propagates the - * change not only to descendants but also to ancestors. With regard to - * descendants this mode behaves exactly like the Propagate mode. With regard to - * ancestors it checks/unchecks them as needed so that a node is unchecked if - * and only if all of its children are unchecked. - * - * @author Boldrini - */ -public class PropagatePreservingUncheckTreeCheckingMode extends TreeCheckingMode { - - PropagatePreservingUncheckTreeCheckingMode(DefaultTreeCheckingModel model) { - super(model); - } - - @Override - public void checkPath(TreePath path) { - // check is propagated to children - this.model.checkSubTree(path); - // check all the ancestors with subtrees checked - TreePath[] parents = new TreePath[path.getPathCount()]; - parents[0] = path; - // boolean uncheckAll = false; - boolean greyAll = false; - for (int i = 1; i < parents.length; i++) { - parents[i] = parents[i - 1].getParentPath(); - this.model.addToCheckedPathsSet(parents[i]); - if (greyAll) { - this.model.addToGreyedPathsSet(parents[i]); - } else { - switch (this.model.getChildrenChecking(parents[i])) { - case HALF_CHECKED: - this.model.addToGreyedPathsSet(parents[i]); - greyAll = true; - break; - case ALL_UNCHECKED: - System.err.println("This should not happen (PropagatePreservingUncheckTreeCheckingMode)"); - break; - case ALL_CHECKED: - this.model.removeFromGreyedPathsSet(parents[i]); - break; - default: - case NO_CHILDREN: - System.err.println("This should not happen (PropagatePreservingCheckTreeCheckingMode)"); - break; - } - } - } - } - - @Override - public void uncheckPath(TreePath path) { - // uncheck is propagated to children - this.model.uncheckSubTree(path); - TreePath parentPath = path; - // check all the ancestors with subtrees checked - while ((parentPath = parentPath.getParentPath()) != null) { - switch (this.model.getChildrenChecking(parentPath)) { - case HALF_CHECKED: - this.model.addToCheckedPathsSet(parentPath); - this.model.addToGreyedPathsSet(parentPath); - break; - case ALL_UNCHECKED: - this.model.removeFromCheckedPathsSet(parentPath); - this.model.removeFromGreyedPathsSet(parentPath); - break; - case ALL_CHECKED: - System.err.println("This should not happen (PropagatePreservingUncheckTreeCheckingMode)"); - break; - default: - case NO_CHILDREN: - System.err.println("This should not happen (PropagatePreservingCheckTreeCheckingMode)"); - break; - } - } - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterChildrenInserted(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterChildrenInserted(TreePath parent) { - if (this.model.isPathChecked(parent)) { - this.model.checkSubTree(parent); - } else { - this.model.uncheckSubTree(parent); - } - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterChildrenRemoved(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterChildrenRemoved(TreePath parent) { - if (this.model.isPathChecked(parent)) { - // System.out.println(parent +" was removed (not checked)"); - if (this.model.getChildrenPath(parent).length != 0) { - if (!this.model.pathHasChildrenWithValue(parent, true)) { - // System.out.println("uncheking it"); - uncheckPath(parent); - } - } - } - this.model.updatePathGreyness(parent); - this.model.updateAncestorsGreyness(parent); - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterStructureChanged(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterStructureChanged(TreePath parent) { - if (this.model.isPathChecked(parent)) { - checkPath(parent); - } else { - uncheckPath(parent); - } - } - -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagateTreeCheckingMode.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagateTreeCheckingMode.java deleted file mode 100644 index 490834ce9b..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagateTreeCheckingMode.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import javax.swing.tree.TreePath; - -/** - * PropagateTreeCheckingMode define a TreeCheckingMode with down recursion of - * the check when nodes are clicked. It toggles the just-clicked checkbox and - * propagates the change down. In other words, if the clicked checkbox is - * checked all the descendants will be checked; otherwise all the descendants - * will be unchecked. - * - * @author Boldrini - */ -public class PropagateTreeCheckingMode extends TreeCheckingMode { - - PropagateTreeCheckingMode(DefaultTreeCheckingModel model) { - super(model); - } - - @Override - public void checkPath(TreePath path) { - this.model.checkSubTree(path); - this.model.updatePathGreyness(path); - this.model.updateAncestorsGreyness(path); - } - - @Override - public void uncheckPath(TreePath path) { - this.model.uncheckSubTree(path); - this.model.updatePathGreyness(path); - this.model.updateAncestorsGreyness(path); - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterChildrenInserted(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterChildrenInserted(TreePath parent) { - if (this.model.isPathChecked(parent)) { - this.model.checkSubTree(parent); - } else { - this.model.uncheckSubTree(parent); - } - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterChildrenRemoved(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterChildrenRemoved(TreePath parent) { - this.model.updatePathGreyness(parent); - this.model.updateAncestorsGreyness(parent); - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterStructureChanged(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterStructureChanged(TreePath parent) { - if (this.model.isPathChecked(parent)) { - this.model.checkSubTree(parent); - } else { - this.model.uncheckSubTree(parent); - } - } - -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagateUpWhiteTreeCheckingMode.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagateUpWhiteTreeCheckingMode.java deleted file mode 100644 index 931b02f361..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/PropagateUpWhiteTreeCheckingMode.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import javax.swing.tree.TreePath; - -/** - * PropagateUpWhiteTreeCheckingMode define a TreeCheckingMode with down - * recursion of the check when nodes are clicked and up only when uncheck. The - * check is propagated, like the Propagate mode to descendants. If a user - * unchecks a checkbox the uncheck will also be propagated to ancestors. - * - * @author Boldrini - */ -public class PropagateUpWhiteTreeCheckingMode extends TreeCheckingMode { - - PropagateUpWhiteTreeCheckingMode(DefaultTreeCheckingModel model) { - super(model); - } - - @Override - public void checkPath(TreePath path) { - // check is propagated to children - this.model.checkSubTree(path); - // check all the ancestors with subtrees checked - TreePath[] parents = new TreePath[path.getPathCount()]; - parents[0] = path; - TreePath parentPath = path; - // uncheck is propagated to parents, too - while ((parentPath = parentPath.getParentPath()) != null) { - this.model.updatePathGreyness(parentPath); - } - } - - @Override - public void uncheckPath(TreePath path) { - // uncheck is propagated to children - this.model.uncheckSubTree(path); - TreePath parentPath = path; - // uncheck is propagated to parents, too - while ((parentPath = parentPath.getParentPath()) != null) { - this.model.removeFromCheckedPathsSet(parentPath); - this.model.updatePathGreyness(parentPath); - } - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterChildrenInserted(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterChildrenInserted(TreePath parent) { - if (this.model.isPathChecked(parent)) { - checkPath(parent); - } else { - uncheckPath(parent); - } - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterChildrenRemoved(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterChildrenRemoved(TreePath parent) { - if (!this.model.isPathChecked(parent)) { - // System.out.println(parent +" was removed (not checked)"); - if (this.model.getChildrenPath(parent).length != 0) { - if (!this.model.pathHasChildrenWithValue(parent, false)) { - // System.out.println("uncheking it"); - checkPath(parent); - } - } - } - this.model.updatePathGreyness(parent); - this.model.updateAncestorsGreyness(parent); - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterStructureChanged(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterStructureChanged(TreePath parent) { - if (this.model.isPathChecked(parent)) { - checkPath(parent); - } else { - uncheckPath(parent); - } - } - -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/QuadristateButtonModel.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/QuadristateButtonModel.java deleted file mode 100644 index 368ead4552..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/QuadristateButtonModel.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import javax.swing.DefaultButtonModel; - -/** - * The model for a quadristate CheckBox. Available states are UNCHECKED, - * CHECKED, GREY_CHECKED, GREY_UNCHECKED - * - * @author boldrini - */ -public class QuadristateButtonModel extends DefaultButtonModel { - - public enum State { - UNCHECKED, CHECKED, GREY_CHECKED, GREY_UNCHECKED - } - - public QuadristateButtonModel() { - super(); - setState(State.UNCHECKED); - } - - /** Filter: No one may change the armed status except us. */ - @Override - public void setArmed(boolean b) { - } - - // public void setSelected(boolean b) { - // if (b) { - // setState(State.CHECKED); - // } else { - // setState(State.UNCHECKED); - // } - // } - - public void setState(State state) { - switch (state) { - case UNCHECKED: - super.setArmed(false); - setPressed(false); - setSelected(false); - break; - case CHECKED: - super.setArmed(false); - setPressed(false); - setSelected(true); - break; - case GREY_UNCHECKED: - super.setArmed(true); - setPressed(true); - setSelected(false); - break; - case GREY_CHECKED: - super.setArmed(true); - setPressed(true); - setSelected(true); - break; - } - } - - /** - * The current state is embedded in the selection / armed state of the - * model. We return the CHECKED state when the checkbox is selected but - * not armed, GREY_CHECKED state when the checkbox is selected and armed - * (grey) and UNCHECKED when the checkbox is deselected. - */ - public State getState() { - if (isSelected() && !isArmed()) { - // CHECKED - return State.CHECKED; - } else if (isSelected() && isArmed()) { - // GREY_CHECKED - return State.GREY_CHECKED; - } else if (!isSelected() && isArmed()) { - // GREY_UNCHECKED - return State.GREY_UNCHECKED; - } else { // (!isSelected() && !isArmed()){ - // UNCHECKED - return State.UNCHECKED; - } - } - - /** - * We rotate between UNCHECKED, CHECKED, GREY_UNCHECKED, GREY_CHECKED. - */ - public void nextState() { - switch (getState()) { - case UNCHECKED: - setState(State.CHECKED); - break; - case CHECKED: - setState(State.GREY_UNCHECKED); - break; - case GREY_UNCHECKED: - setState(State.GREY_CHECKED); - break; - case GREY_CHECKED: - setState(State.UNCHECKED); - break; - } - } -} diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/QuadristateCheckbox.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/QuadristateCheckbox.java deleted file mode 100644 index b1685c48b8..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/QuadristateCheckbox.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import net.sourceforge.pmd.jedit.checkboxtree.QuadristateButtonModel.State; - -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.ButtonModel; -import javax.swing.Icon; -import javax.swing.JCheckBox; -import javax.swing.SwingUtilities; -import javax.swing.plaf.ActionMapUIResource; - -/** - * Checkbox with four states. Available states are UNCHECKED, CHECKED, - * GREY_CHECKED, GREY_UNCHECKED. The rendering is obtained via a visualization - * hack. The checkbox exploits the different rendering (greyed) of checkbox - * pressed, thus the press, arm, rollover events are not available. Maintenance - * tip - There were some tricks to getting this code working: 1. You have to - * overwite addMouseListener() to do nothing 2. You have to add a mouse event on - * mousePressed by calling super.addMouseListener() 3. You have to replace the - * UIActionMap for the keyboard event "pressed" with your own one. 4. You have - * to remove the UIActionMap for the keyboard event "released". 5. You have to - * grab focus when the next state is entered, otherwise clicking on the - * component won't get the focus. - * - * @author boldrini - * @author bigagli - */ - -public class QuadristateCheckbox extends JCheckBox { - - public QuadristateCheckbox(String text, Icon icon, State state) { - super(text, icon); - // Add a listener for when the mouse is pressed - super.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - grabFocus(); - getModel().nextState(); - } - }); - // Reset the keyboard action map - ActionMap map = new ActionMapUIResource(); - map.put("pressed", new AbstractAction() { - public void actionPerformed(ActionEvent e) { - grabFocus(); - getModel().nextState(); - } - }); - map.put("released", null); - SwingUtilities.replaceUIActionMap(this, map); - setState(state); - } - - public QuadristateCheckbox(String text, State initial) { - this(text, null, initial); - } - - public QuadristateCheckbox(String text) { - this(text, State.UNCHECKED); - } - - public QuadristateCheckbox() { - this(null); - } - - @Override - protected void init(String text, Icon icon) { - // substitutes the underlying checkbox model: - // if we had call setModel an exception would be raised - // because setModel calls a getModel that return a - // QuadristateButtonModel, but at this point we - // have a JToggleButtonModel - this.model = new QuadristateButtonModel(); - super.setModel(this.model); // side effect: set listeners - super.init(text, icon); - } - - @Override - public QuadristateButtonModel getModel() { - return (QuadristateButtonModel) super.getModel(); - } - - public void setModel(QuadristateButtonModel model) { - super.setModel(model); - } - - @Override - @Deprecated - public void setModel(ButtonModel model) { - // if (!(model instanceof TristateButtonModel)) - // useless: Java always calls the most specific method - super.setModel(model); - } - - /** No one may add mouse listeners, not even Swing! */ - @Override - public void addMouseListener(MouseListener l) { - } - - /** - * Set the new state to either CHECKED, UNCHECKED or GREY_CHECKED. If - * state == null, it is treated as GREY_CHECKED. - */ - public void setState(State state) { - getModel().setState(state); - } - - /** - * Return the current state, which is determined by the selection status - * of the model. - */ - public State getState() { - return getModel().getState(); - } - -} diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/SimpleTreeCheckingMode.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/SimpleTreeCheckingMode.java deleted file mode 100644 index bf3a0f483f..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/SimpleTreeCheckingMode.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import javax.swing.tree.TreePath; - -/** - * SimpleTreeCheckingMode defines a TreeCheckingMode without recursion. In this - * simple mode the check state always changes only the current node: no - * recursion. - * - * @author Boldrini - */ -public class SimpleTreeCheckingMode extends TreeCheckingMode { - - SimpleTreeCheckingMode(DefaultTreeCheckingModel model) { - super(model); - } - - @Override - public void checkPath(TreePath path) { - this.model.addToCheckedPathsSet(path); - this.model.updatePathGreyness(path); - this.model.updateAncestorsGreyness(path); - } - - @Override - public void uncheckPath(TreePath path) { - this.model.removeFromCheckedPathsSet(path); - this.model.updatePathGreyness(path); - this.model.updateAncestorsGreyness(path); - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterChildrenInserted(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterChildrenInserted(TreePath parent) { - this.model.updatePathGreyness(parent); - this.model.updateAncestorsGreyness(parent); - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterChildrenRemoved(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterChildrenRemoved(TreePath parent) { - this.model.updatePathGreyness(parent); - this.model.updateAncestorsGreyness(parent); - } - - /* - * (non-Javadoc) - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingMode#updateCheckAfterStructureChanged(javax.swing.tree.TreePath) - */ - @Override - public void updateCheckAfterStructureChanged(TreePath parent) { - this.model.updatePathGreyness(parent); - this.model.updateAncestorsGreyness(parent); - } - -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingEvent.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingEvent.java deleted file mode 100644 index 55fe840c0f..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import java.util.EventObject; - -import javax.swing.tree.TreePath; - -/** - * An event that characterizes a change in the current checking. - * - * @author boldrini - */ -public class TreeCheckingEvent extends EventObject { - /** Paths this event represents. */ - protected TreePath leadingPath; - - /** - * Returns the paths that have been added or removed from the selection. - */ - public TreePath getLeadingPath() { - return this.leadingPath; - } - - public TreeCheckingEvent(TreePath path) { - super(path); - this.leadingPath = path; - } - -} diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingListener.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingListener.java deleted file mode 100644 index a865db75c3..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingListener.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import java.util.EventListener; - -/** - * The listener that's notified when the checking in a TreeCheckingModel - * changes. - * - * @see net.sourceforge.pmd.jedit.checkboxtree.TreeCheckingModel - * @see net.sourceforge.pmd.jedit.checkboxtree.CheckboxTree - * @author Enrico Boldrini - */ -public interface TreeCheckingListener extends EventListener { - /** - * Called whenever the value of the checking changes. - * - * @param e the event that characterizes the change. - */ - void valueChanged(TreeCheckingEvent e); -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingMode.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingMode.java deleted file mode 100644 index 3f68761b34..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingMode.java +++ /dev/null @@ -1,82 +0,0 @@ -/* -* Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of -* CheckboxTree. CheckboxTree is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or (at your -* option) any later version. CheckboxTree is distributed in the hope that it -* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -* Public License for more details. You should have received a copy of the GNU -* General Public License along with CheckboxTree; if not, write to the Free -* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA -*/ -package net.sourceforge.pmd.jedit.checkboxtree; - -import javax.swing.tree.TreePath; - -/** - * The model for checking/unchecking the nodes of a CheckboxTree. Alterations - * of a node state may propagate on descendants/ascendants, according to the - * behaviour of the model. Several default behavioural modes are defined. The - * models must use the methods addToCheckedSet and removeFromCheckedSet from - * DefaultTreeCheckingModel to add/remove the single paths from the checking - * set. - * - * @author bigagli - * @author boldrini - */ -public abstract class TreeCheckingMode { - - protected DefaultTreeCheckingModel model; - - // TODO: implementare Strategy in questo modo: TreeCheckingMode classe - // interna al TreeCheckingModel, con un metodo getModel() protetto, - // utile - // alle sottoclassi - TreeCheckingMode( DefaultTreeCheckingModel model ) { - this.model = model; - } - - /** - * Checks the specified path and propagates the checking according to - * the strategy - * - * @param path the path to be added. - */ - - public abstract void checkPath( TreePath path ); - - /** - * Unchecks the specified path and propagates the checking according to - * the strategy - * - * @param path the path to be removed. - */ - public abstract void uncheckPath( TreePath path ); - - /** - * Update the check of the given path after the insertion of some of its - * children, according to the strategy - * - * @param path - */ - public abstract void updateCheckAfterChildrenInserted( TreePath path ); - - /** - * Update the check of the given path after the removal of some of its - * children, according to the strategy - * - * @param path - */ - public abstract void updateCheckAfterChildrenRemoved( TreePath path ); - - /** - * Update the check of the given path after the structure change, - * according to the strategy - * - * @param path - */ - public abstract void updateCheckAfterStructureChanged( TreePath path ); - -} \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingModel.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingModel.java deleted file mode 100644 index 8d72969952..0000000000 --- a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/checkboxtree/TreeCheckingModel.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright 2006,2007 Enrico Boldrini, Lorenzo Bigagli This file is part of - * CheckboxTree. CheckboxTree is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. CheckboxTree is distributed in the hope that it - * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. You should have received a copy of the GNU - * General Public License along with CheckboxTree; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ -package net.sourceforge.pmd.jedit.checkboxtree; - -import javax.swing.event.TreeModelListener; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; - -/** - * The model for checking/unchecking the nodes of a CheckboxTree. Alterations of - * a node state may propagate on descendants/ascendants, according to the - * behaviour of the checking model. See CheckingMode for the available - * behaviours. - * - * @author bigagli - * @author boldrini - */ -public interface TreeCheckingModel { - - /** - * The checking behaviours provided by this class. - * - * @author boldrini - */ - public enum CheckingMode { - - /** - * The check is not propagated at all, toggles the just-clicked checkbox - * only. - */ - SIMPLE, - - /** - * Toggles the just-clicked checkbox and propagates the change down. In - * other words, if the clicked checkbox is checked all the descendants - * will be checked; otherwise all the descendants will be unchecked - */ - PROPAGATE, - - /** - * The check is propagated, like the Propagate mode to descendants. If a - * user unchecks a checkbox the uncheck will also be propagated to - * ancestors. - */ - PROPAGATE_UP_UNCHECK, - - /** - * Propagates the change not only to descendants but also to ancestors. - * With regard to descendants this mode behaves exactly like the - * Propagate mode. With regard to ancestors it checks/unchecks them as - * needed so that a node is unchecked if and only if all of its children - * are unchecked. - */ - PROPAGATE_PRESERVING_UNCHECK, - - /** - * Propagates the change not only to descendants but also to ancestors. - * With regard to descendants this mode behaves exactly like the - * Propagate mode. With regard to ancestors it checks/unchecks them as - * needed so that a node is checked if and only if all of its children - * are checked. - */ - PROPAGATE_PRESERVING_CHECK - } - - /** - * Returns whether the specified path is checked. - */ - public boolean isPathChecked(TreePath path); - - /** - * Returns whether the specified path checking state can be toggled. - */ - public boolean isPathEnabled(TreePath path); - - /** - * Returns whether the specified path is greyed. - */ - public boolean isPathGreyed(TreePath path); - - /** - * Alter (check/uncheck) the checking state of the specified path if - * possible and also propagate the new state if needed by the mode. - */ - public void toggleCheckingPath(TreePath pathForRow); - - /** - * add a path to the checked paths set - * - * @param path the path to be added. - */ - public void addCheckingPath(TreePath path); - - /** - * add paths to the checked paths set - * - * @param paths the paths to be added. - */ - public void addCheckingPaths(TreePath[] paths); - - /** - * remove a path from the checked paths set - * - * @param path the path to be added. - */ - public void removeCheckingPath(TreePath path); - - /** - * remove paths from the checked paths set - * - * @param paths the paths to be added. - */ - public void removeCheckingPaths(TreePath[] paths); - - /** - * Sets whether or not the path is enabled. - * - * @param path the path to enable/disable - */ - public void setPathEnabled(TreePath path, boolean enable); - - /** - * Sets whether or not the paths are enabled. - * - * @param paths the paths to enable/disable - */ - public void setPathsEnabled(TreePath[] paths, boolean enable); - - /** - * @return Returns the paths that are in the checking set. - */ - public TreePath[] getCheckingPaths(); - - /** - * @return Returns the paths that are in the checking set and are the - * (upper) roots of checked trees. - */ - public TreePath[] getCheckingRoots(); - - /** - * @return Returns the paths that are in the greying set. - */ - public TreePath[] getGreyingPaths(); - - /** - * Set the checking to paths. - */ - public void setCheckingPaths(TreePath[] paths); - - /** - * Set the checking to path. - */ - public void setCheckingPath(TreePath path); - - /** - * Clears the checking. - */ - public void clearChecking(); - - /** - * Set the checking mode. - * - * @param mode The checkingMode to set. - */ - public void setCheckingMode(CheckingMode mode); - - /** - * @return Returns the CheckingMode. - */ - public CheckingMode getCheckingMode(); - - /** - * Get the listener for the TreeModelEvent posted after - * the tree changes. - * - * @deprecated use get/setTreeModel instead - */ - @Deprecated - public TreeModelListener getTreeModelListener(); - - /** - * Adds x to the list of listeners that are notified each time the set - * of checking TreePaths changes. - * - * @param x the new listener to be added - */ - public void addTreeCheckingListener(TreeCheckingListener x); - - /** - * Removes x from the list of listeners that are notified each time the - * set of checking TreePaths changes. - * - * @param x the listener to remove - */ - public void removeTreeCheckingListener(TreeCheckingListener x); - - /** - * Returns the tree model to which this checking model is bound, or null - * if not set. - */ - public TreeModel getTreeModel(); - - /** - * Set the tree model to which this checking model is (possibly) bound. - * A checking model may use a tree model to propagate the checking. A - * checking model may also listen to the model, to adjust the checking - * upon model events. The current checking is cleared. - */ - public void setTreeModel(TreeModel model); - -} diff --git a/pmd-netbeans/nbproject/build-impl.xml b/pmd-netbeans/nbproject/build-impl.xml new file mode 100644 index 0000000000..6b86c5739e --- /dev/null +++ b/pmd-netbeans/nbproject/build-impl.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pmd-netbeans/nbproject/genfiles.properties b/pmd-netbeans/nbproject/genfiles.properties new file mode 100644 index 0000000000..ea7f0f55fc --- /dev/null +++ b/pmd-netbeans/nbproject/genfiles.properties @@ -0,0 +1,5 @@ +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=56fe9809 +nbproject/build-impl.xml.script.CRC32=209b78c0 +nbproject/build-impl.xml.stylesheet.CRC32=68e521fc@1.42.2 diff --git a/pmd-netbeans/nbproject/platform.properties b/pmd-netbeans/nbproject/platform.properties new file mode 100644 index 0000000000..2ea90e414b --- /dev/null +++ b/pmd-netbeans/nbproject/platform.properties @@ -0,0 +1,2 @@ +nbjdk.active=default +nbplatform.active=default diff --git a/pmd-netbeans/nbproject/project.properties b/pmd-netbeans/nbproject/project.properties new file mode 100644 index 0000000000..f1c909e2ba --- /dev/null +++ b/pmd-netbeans/nbproject/project.properties @@ -0,0 +1,16 @@ +extra.module.files=\ + modules/ext/jaxen-1.1.1.jar \ + modules/ext/pmd-4.2.5.jar \ + modules/ext/asm-3.1.jar \ + modules/ext/nbpmdrules.jar +javac.compilerargs=-Xlint:unchecked +javac.source=1.5 +nbm.distribution=http://pmd.sourceforge.net/ + +license.file=LICENSE.txt +nbm.homepage=http://pmd.sourceforge.net/ +nbm.module.author=Ole-Martin M\u00f8rk, Gunnlaugur \u00de\u00f3r Briem, Radim Kubacki, Tomasz Slota +#netbeans.dest.dir - absolute pathname of NB platform (or IDE or whatever) that +#you are building your module against, and into which your module will be built. +#Available in project.properties. + diff --git a/pmd-netbeans/nbproject/project.xml b/pmd-netbeans/nbproject/project.xml new file mode 100644 index 0000000000..752928a7de --- /dev/null +++ b/pmd-netbeans/nbproject/project.xml @@ -0,0 +1,222 @@ + + + org.netbeans.modules.apisupport.project + + + pmd + + + + + org.jdesktop.layout + + + + 1 + 1.3.1 + + + + org.netbeans.api.java + + + + 1 + + + + org.netbeans.api.java.classpath + + + + 1 + 1.18 + + + + org.netbeans.api.progress + + + + 1 + 1.0 + + + + org.netbeans.modules.editor + + + + 3 + 1.41 + + + + org.netbeans.modules.editor.indent + + + + 2 + 1.9 + + + + org.netbeans.modules.editor.settings + + + + 1 + 1.22 + + + + org.netbeans.modules.java.source + + + + 0.12.0.1.4 + + + + org.netbeans.modules.options.api + + + + 1 + 1.5 + + + + org.netbeans.modules.queries + + + + 1 + 1.10 + + + + org.openide.awt + + + + 6.2 + + + + org.openide.dialogs + + + + 6.5.1 + + + + org.openide.filesystems + + + + 6.2 + + + + org.openide.io + + + + 1.0 + + + + org.openide.loaders + + + + + + org.openide.modules + + + + 6.2 + + + + org.openide.nodes + + + + 6.2 + + + + org.openide.text + + + + 6.16 + + + + org.openide.util + + + + 7.4 + + + + org.openide.windows + + + + 6.2 + + + + + + unit + + pmd + + + + + org.netbeans.modules.masterfs + + + org.netbeans.modules.nbjunit + + + + + + + + + ext/asm-3.1.jar + + lib/asm-3.1.jar + + + ext/jaxen-1.1.1.jar + lib/jaxen-1.1.1.jar + + + ext/pmd-4.2.5.jar + lib/pmd-4.2.5.jar + + + + ext/nbpmdrules.jar + + + libsrc + lib/pmd-4.2.5.jar + build/libclasses + ${cluster}/modules/ext/nbpmdrules.jar + + + + diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 1e3ec1ca6d..0f163b45f8 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,11 +1,25 @@ ???? ??, 2012 - 5.1.0: +Fixed bug 878: False positive: UnusedFormalParameter for abstract methods +Fixed bug 913: SignatureDeclareThrowsException is raised twice +Fixed bug 947: CloseResource rule fails if field is marked with annotation +Fixed bug 1007: Parse Exception with annotation +Fixed bug 1011: CloseResource Rule ignores Constructors +Fixed bug 1012: False positive: Useless parentheses. +Fixed bug 1020: Parsing Error Fixed bug 1026: PMD doesn't handle 'value =' in SuppressWarnings annotation +Fixed bug 1028: False-positive: Compare objects with equals for Enums +Fixed bug 1030: CPD Java.lang.IndexOutOfBoundsException: Index: Fixed bug 1037: Facing a showstopper issue in PMD Report Class (report listeners) +Fixed bug 1039: pmd-nicerhtml.xsl is packaged in wrong location Fixed bug 1043: node.getEndLine() always returns 0 (ECMAscript) Fixed bug 1044: Unknown option: -excludemarker +Fixed bug 1046: ant task CPDTask doesn't accept ecmascript Fixed bug 1047: False Positive in 'for' loops for LocalVariableCouldBeFinal in 5.0.1 Fixed bug 1048: CommentContent Rule, String Index out of range Exception +Fixed bug 1055: Please add a colon in the ant output after line,column for Oracle JDeveloper IDE usage +Fixed bug 1059: Change rule name "Use Singleton" should be "Use Utility class" +Fixed bug 1060: GodClassRule >>> wrong method ????? ??, 2013 - 5.0.2: diff --git a/pmd/etc/grammar/Java.jjt b/pmd/etc/grammar/Java.jjt index 8ae6df0b5f..3e4d8cb681 100644 --- a/pmd/etc/grammar/Java.jjt +++ b/pmd/etc/grammar/Java.jjt @@ -1,4 +1,8 @@ /** + * Fix ForStatement to allow Annotations within the initializer. + * + * Andreas Dangel 01/2013 + * =================================================================== * Fix wrong consumption of modifiers (e.g. "final") in a for-each loop. * Check for wrong java usage when catching multiple exceptions. * @@ -1939,7 +1943,7 @@ void ForStatement() : void ForInit() : {} { - LOOKAHEAD( [ "final" ] Type() ) + LOOKAHEAD( LocalVariableDeclaration() ) LocalVariableDeclaration() | StatementExpressionList() diff --git a/pmd/pom.xml b/pmd/pom.xml index e769a223b9..bca3a604f1 100644 --- a/pmd/pom.xml +++ b/pmd/pom.xml @@ -291,6 +291,7 @@ once -Xmx512m -Dfile.encoding=${project.build.sourceEncoding} + alphabetical @@ -299,7 +300,6 @@ 1.5 1.5 - true diff --git a/pmd/src/main/java/net/sourceforge/pmd/cpd/CPD.java b/pmd/src/main/java/net/sourceforge/pmd/cpd/CPD.java index 6dac9e385e..5680b89981 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/cpd/CPD.java +++ b/pmd/src/main/java/net/sourceforge/pmd/cpd/CPD.java @@ -26,6 +26,8 @@ public class CPD { public CPD(CPDConfiguration theConfiguration) { configuration = theConfiguration; + // before we start any tokenizing (add(File...)), we need to reset the static TokenEntry status + TokenEntry.clearImages(); } public void setCpdListener(CPDListener cpdListener) { @@ -33,7 +35,6 @@ public class CPD { } public void go() { - TokenEntry.clearImages(); matchAlgorithm = new MatchAlgorithm(source, tokens,configuration.getMinimumTileSize(),listener); matchAlgorithm.findMatches(); } diff --git a/pmd/src/main/java/net/sourceforge/pmd/cpd/CPDTask.java b/pmd/src/main/java/net/sourceforge/pmd/cpd/CPDTask.java index 59a623e8bc..e2a600a049 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/cpd/CPDTask.java +++ b/pmd/src/main/java/net/sourceforge/pmd/cpd/CPDTask.java @@ -190,16 +190,9 @@ public class CPDTask extends Task { } } - /* - * FIXME Can't we do something cleaner and - * more dynamic ? Maybe externalise to a properties files that will - * be generated when building pmd ? This will not have to add manually - * new language here ? - */ public static class LanguageAttribute extends EnumeratedAttribute { - private static final String[] LANGUAGES = new String[]{"java","jsp","cpp", "c","php", "ruby", "fortran", "cs"}; public String[] getValues() { - return LANGUAGES; + return LanguageFactory.supportedLanguages; } } } diff --git a/pmd/src/main/java/net/sourceforge/pmd/cpd/GUI.java b/pmd/src/main/java/net/sourceforge/pmd/cpd/GUI.java index a0c1e21056..67a222e8ef 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/cpd/GUI.java +++ b/pmd/src/main/java/net/sourceforge/pmd/cpd/GUI.java @@ -107,19 +107,22 @@ public class GUI implements CPDListener { {"Fortran", new LanguageConfig() { public Language languageFor(LanguageFactory lf, Properties p) { return lf.createLanguage("fortran"); } public String[] extensions() { return new String[] {".rb" }; }; } }, - {"by extension...", new LanguageConfig() { - public Language languageFor(LanguageFactory lf, Properties p) { return lf.createLanguage(LanguageFactory.BY_EXTENSION, p); } - public String[] extensions() { return new String[] {"" }; }; } }, - {"PHP", new LanguageConfig() { + {"PHP", new LanguageConfig() { public Language languageFor(LanguageFactory lf, Properties p) { return lf.createLanguage("php"); } public String[] extensions() { return new String[] {".php" }; }; } }, - {"C#", new LanguageConfig() { + {"C#", new LanguageConfig() { public Language languageFor(LanguageFactory lf, Properties p) { return lf.createLanguage("cs"); } public String[] extensions() { return new String[] {".cs" }; }; } }, + {"Ecmascript", new LanguageConfig() { + public Language languageFor(LanguageFactory lf, Properties p) { return lf.createLanguage("js"); } + public String[] extensions() { return new String[] {".js" }; }; } }, + {"by extension...", new LanguageConfig() { + public Language languageFor(LanguageFactory lf, Properties p) { return lf.createLanguage(LanguageFactory.BY_EXTENSION, p); } + public String[] extensions() { return new String[] {"" }; }; } }, }; private static final int DEFAULT_CPD_MINIMUM_LENGTH = 75; - private static final Map LANGUAGE_CONFIGS_BY_LABEL = new HashMap(LANGUAGE_SETS.length); + private static final Map LANGUAGE_CONFIGS_BY_LABEL = new HashMap(LANGUAGE_SETS.length); private static final KeyStroke COPY_KEY_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK,false); private static final KeyStroke DELETE_KEY_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0); @@ -149,12 +152,12 @@ public class GUI implements CPDListener { static { for (int i=0; i vars = node.findDescendantsOfType(ASTLocalVariableDeclaration.class); List ids = new ArrayList(); @@ -85,7 +97,7 @@ public class CloseResourceRule extends AbstractJavaRule { if (ref.jjtGetChild(0) instanceof ASTClassOrInterfaceType) { ASTClassOrInterfaceType clazz = (ASTClassOrInterfaceType) ref.jjtGetChild(0); if (types.contains(clazz.getImage())) { - ASTVariableDeclaratorId id = (ASTVariableDeclaratorId) var.jjtGetChild(1).jjtGetChild(0); + ASTVariableDeclaratorId id = var.getFirstDescendantOfType(ASTVariableDeclaratorId.class); ids.add(id); } } @@ -96,7 +108,6 @@ public class CloseResourceRule extends AbstractJavaRule { for (ASTVariableDeclaratorId x : ids) { ensureClosed((ASTLocalVariableDeclaration) x.jjtGetParent().jjtGetParent(), x, data); } - return data; } private void ensureClosed(ASTLocalVariableDeclaration var, @@ -107,11 +118,11 @@ public class CloseResourceRule extends AbstractJavaRule { String target = variableToClose + ".close"; Node n = var; - while (!(n instanceof ASTBlock)) { + while (!(n instanceof ASTBlock) && !(n instanceof ASTConstructorDeclaration)) { n = n.jjtGetParent(); } - ASTBlock top = (ASTBlock) n; + Node top = n; List tryblocks = top.findDescendantsOfType(ASTTryStatement.class); @@ -206,7 +217,7 @@ public class CloseResourceRule extends AbstractJavaRule { List returns = new ArrayList(); top.findDescendantsOfType(ASTReturnStatement.class, returns, true); for (ASTReturnStatement returnStatement : returns) { - ASTName name = returnStatement.getFirstChildOfType(ASTName.class); + ASTName name = returnStatement.getFirstDescendantOfType(ASTName.class); if ((name != null) && name.getImage().equals(variableToClose)) { closed = true; break; @@ -216,7 +227,7 @@ public class CloseResourceRule extends AbstractJavaRule { // if all is not well, complain if (!closed) { - ASTType type = (ASTType) var.jjtGetChild(0); + ASTType type = var.getFirstChildOfType(ASTType.class); ASTReferenceType ref = (ASTReferenceType) type.jjtGetChild(0); ASTClassOrInterfaceType clazz = (ASTClassOrInterfaceType) ref.jjtGetChild(0); addViolation(data, id, clazz.getImage()); diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CompareObjectsWithEqualsRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CompareObjectsWithEqualsRule.java index a858ea32de..d0503b38ab 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CompareObjectsWithEqualsRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CompareObjectsWithEqualsRule.java @@ -5,6 +5,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression; import net.sourceforge.pmd.lang.java.ast.ASTEqualityExpression; import net.sourceforge.pmd.lang.java.ast.ASTInitializer; import net.sourceforge.pmd.lang.java.ast.ASTName; +import net.sourceforge.pmd.lang.java.ast.ASTReferenceType; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; import net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration; @@ -65,6 +66,14 @@ public class CompareObjectsWithEqualsRule extends AbstractJavaRule { } if (nd0.isReferenceType() && nd1.isReferenceType()) { + + ASTReferenceType type0 = (ASTReferenceType)((Node) nd0.getAccessNodeParent()).jjtGetChild(0).jjtGetChild(0); + ASTReferenceType type1 = (ASTReferenceType)((Node) nd1.getAccessNodeParent()).jjtGetChild(0).jjtGetChild(0); + // skip, if it is an enum + if (type0.getType() != null && type0.getType().equals(type1.getType()) && type0.getType().isEnum()) { + return data; + } + addViolation(data, node); } } diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java index 939f1d7cdb..74e7560f75 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java @@ -154,18 +154,20 @@ public class GodClassRule extends AbstractJavaRule { int pairs = 0; if (methodCount > 1) { - for (int i = 0; i < methodCount - 1; i++) { - String firstMethodName = methods.get(i); - String secondMethodName = methods.get(i + 1); - Set accessesOfFirstMethod = methodAttributeAccess.get(firstMethodName); - Set accessesOfSecondMethod = methodAttributeAccess.get(secondMethodName); - Set combinedAccesses = new HashSet(); - - combinedAccesses.addAll(accessesOfFirstMethod); - combinedAccesses.addAll(accessesOfSecondMethod); - - if (combinedAccesses.size() < (accessesOfFirstMethod.size() + accessesOfSecondMethod.size())) { - pairs++; + for (int i = 0; i < methodCount; i++) { + for (int j = i + 1; j < methodCount; j++) { + String firstMethodName = methods.get(i); + String secondMethodName = methods.get(j); + Set accessesOfFirstMethod = methodAttributeAccess.get(firstMethodName); + Set accessesOfSecondMethod = methodAttributeAccess.get(secondMethodName); + Set combinedAccesses = new HashSet(); + + combinedAccesses.addAll(accessesOfFirstMethod); + combinedAccesses.addAll(accessesOfSecondMethod); + + if (combinedAccesses.size() < (accessesOfFirstMethod.size() + accessesOfSecondMethod.size())) { + pairs++; + } } } } diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/UseSingletonRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/UseUtilityClassRule.java similarity index 98% rename from pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/UseSingletonRule.java rename to pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/UseUtilityClassRule.java index c6096842e3..21edafa2b8 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/UseSingletonRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/UseUtilityClassRule.java @@ -14,7 +14,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTResultType; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; -public class UseSingletonRule extends AbstractJavaRule { +public class UseUtilityClassRule extends AbstractJavaRule { @Override public Object visit(ASTClassOrInterfaceBody decl, Object data) { diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/SignatureDeclareThrowsExceptionRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/SignatureDeclareThrowsExceptionRule.java index e08cfa1dba..82f34ddd9c 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/SignatureDeclareThrowsExceptionRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/SignatureDeclareThrowsExceptionRule.java @@ -1,5 +1,6 @@ package net.sourceforge.pmd.lang.java.rule.strictexception; +import java.util.Collections; import java.util.List; import net.sourceforge.pmd.lang.ast.Node; @@ -8,6 +9,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTName; +import net.sourceforge.pmd.lang.java.ast.ASTNameList; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; /** @@ -46,7 +48,11 @@ public class SignatureDeclareThrowsExceptionRule extends AbstractJavaRule { return super.visit(methodDeclaration, o); } - List exceptionList = methodDeclaration.findDescendantsOfType(ASTName.class); + List exceptionList = Collections.emptyList(); + ASTNameList nameList = methodDeclaration.getFirstChildOfType(ASTNameList.class); + if (nameList != null) { + exceptionList = nameList.findDescendantsOfType(ASTName.class); + } if (!exceptionList.isEmpty()) { evaluateExceptions(exceptionList, o); } diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/unusedcode/UnusedFormalParameterRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/unusedcode/UnusedFormalParameterRule.java index 44a5673697..a3a0a921cf 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/unusedcode/UnusedFormalParameterRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/unusedcode/UnusedFormalParameterRule.java @@ -33,7 +33,7 @@ public class UnusedFormalParameterRule extends AbstractJavaRule { if (!node.isPrivate() && !getProperty(CHECKALL_DESCRIPTOR)) { return data; } - if (!node.isNative()) { + if (!node.isNative() && !node.isAbstract()) { check(node, data); } return data; diff --git a/pmd/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java b/pmd/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java index f606244b29..c938d5eb4f 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java +++ b/pmd/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java @@ -45,7 +45,7 @@ public class TextRenderer extends AbstractIncrementingRenderer { RuleViolation rv = violations.next(); buf.append(rv.getFilename()); buf.append(':').append(Integer.toString(rv.getBeginLine())); - buf.append('\t').append(rv.getDescription()).append(PMD.EOL); + buf.append(":\t").append(rv.getDescription()).append(PMD.EOL); writer.write(buf.toString()); } } diff --git a/pmd/src/main/java/net/sourceforge/pmd/renderers/XSLTRenderer.java b/pmd/src/main/java/net/sourceforge/pmd/renderers/XSLTRenderer.java index 4d8d4df7a2..aa23b337ea 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/renderers/XSLTRenderer.java +++ b/pmd/src/main/java/net/sourceforge/pmd/renderers/XSLTRenderer.java @@ -42,7 +42,7 @@ public class XSLTRenderer extends XMLRenderer { public static final StringProperty XSLT_FILENAME = new StringProperty("xsltFilename", "The XSLT file name.", null, 0); private Transformer transformer; - private String xsltFilename = "/etc/pmd-nicerhtml.xsl"; + private String xsltFilename = "/pmd-nicerhtml.xsl"; private Writer outputWriter; public XSLTRenderer() { @@ -59,11 +59,11 @@ public class XSLTRenderer extends XMLRenderer { */ @Override public void start() throws IOException { - String xsltFilename = getProperty(XSLT_FILENAME); - if (xsltFilename != null) { - File file = new File(xsltFilename); + String xsltFilenameProperty = getProperty(XSLT_FILENAME); + if (xsltFilenameProperty != null) { + File file = new File(xsltFilenameProperty); if (file.exists() && file.canRead()) { - this.xsltFilename = xsltFilename; + this.xsltFilename = xsltFilenameProperty; } } @@ -79,10 +79,10 @@ public class XSLTRenderer extends XMLRenderer { if (file.exists() && file.canRead()) { xslt = new FileInputStream(file); } else { - xslt = this.getClass().getResourceAsStream(xsltFilename); + xslt = this.getClass().getResourceAsStream(this.xsltFilename); } if (xslt == null) { - throw new FileNotFoundException("Can't file XSLT sheet :" + xsltFilename); + throw new FileNotFoundException("Can't file XSLT sheet :" + this.xsltFilename); } this.prepareTransformer(xslt); // Now we build the XML file diff --git a/pmd/src/main/resources/rulesets/java/design.xml b/pmd/src/main/resources/rulesets/java/design.xml index 524563866b..bf04be54cd 100644 --- a/pmd/src/main/resources/rulesets/java/design.xml +++ b/pmd/src/main/resources/rulesets/java/design.xml @@ -10,23 +10,24 @@ The Design ruleset contains rules that flag suboptimal code implementations. Alt are suggested. - + message="All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning." + class="net.sourceforge.pmd.lang.java.rule.design.UseUtilityClassRule" + externalInfoUrl="${pmd.website.baseurl}/rules/java/design.html#UseUtilityClass"> 3 Update the "download" and "what's new" link in site.pre.xml.
  • Update version/release info in etc/changelog.txt.
  • Update pmd.website.baseurl in pom.xml
  • +
  • Update ../website/.htaccess of our website, to redirect to the new version
  • diff --git a/pmd/src/site/xdocs/rule-guidelines.xml b/pmd/src/site/xdocs/rule-guidelines.xml index 09989081bd..d0dee265ad 100644 --- a/pmd/src/site/xdocs/rule-guidelines.xml +++ b/pmd/src/site/xdocs/rule-guidelines.xml @@ -56,17 +56,17 @@ to Jaxen overhead for AST navigation. Make sure your XPath rules using the Rule
    -

    In the regress directory, you'll find all the unit tests for PMD. In the - proper package (for instance, test.net.sourceforge.pmd.rules.basic, for +

    In the test directory (src/test/java), you'll find all the unit tests for PMD. In the + proper package (for instance, net.sourceforge.pmd.lang.java.rule.basic, for rules from the basic rulesets), you'll find a test suite such as this :

    Suppose you want to add tests for a new rule of yours, called "MyNewRule". @@ -74,12 +74,12 @@ public class BasicRulesTest extends SimpleAggregatorTst { -

    And add in the appropriate xml subpackage (for instance, - test.net.sourceforge.pmd.rules.basic.xml). There you should find a XML file +

    And add in the appropriate xml subpackage in src/test/resources (for instance, + net.sourceforge.pmd.lang.java.rule.basic.xml). There you should find a XML file for each rule, the syntax is pretty obvious:

    @@ -109,7 +109,7 @@ package too.specific.to.submit; import org.junit.Before; -import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; +import net.sourceforge.pmd.testframework.SimpleAggregatorTst; public class SpecificRulesTest extends SimpleAggregatorTst { @@ -140,8 +140,9 @@ If you want to contribute a java rule to PMD, you should run PMD on it (Using th

    -Before committing changes, make sure the 'qa' target in the Ant build works. Drink a beer while you wait for it to finish. -Then read the output to make sure no fatal errors are present. +Before committing changes, make sure the verify phase of a maven build succeeds without test failures. +Drink a beer while you wait for it to finish. +Then read the output to make sure no fatal errors are present.

    diff --git a/pmd/src/test/java/net/sourceforge/pmd/ReportTest.java b/pmd/src/test/java/net/sourceforge/pmd/ReportTest.java index 3efd2c7a0f..063fddff2d 100644 --- a/pmd/src/test/java/net/sourceforge/pmd/ReportTest.java +++ b/pmd/src/test/java/net/sourceforge/pmd/ReportTest.java @@ -31,7 +31,7 @@ import org.junit.Test; public class ReportTest extends RuleTst implements ReportListener { - private static class FooRule extends AbstractJavaRule { + public static class FooRule extends AbstractJavaRule { public Object visit(ASTClassOrInterfaceDeclaration c, Object ctx) { if ("Foo".equals(c.getImage())) addViolation(ctx, c); return ctx; @@ -219,7 +219,7 @@ public class ReportTest extends RuleTst implements ReportListener { assertTrue(summary.values().contains(Integer.valueOf(2))); } - private JavaNode getNode(int line, int column, String scopeName){ + public static JavaNode getNode(int line, int column, String scopeName){ DummyJavaNode s = new DummyJavaNode(2); DummyJavaNode parent = new DummyJavaNode(1); parent.testingOnly__setBeginLine(line); diff --git a/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/design/DesignRulesTest.java b/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/design/DesignRulesTest.java index f7cdcbb868..e09a636368 100644 --- a/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/design/DesignRulesTest.java +++ b/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/design/DesignRulesTest.java @@ -1,3 +1,6 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ package net.sourceforge.pmd.lang.java.rule.design; import net.sourceforge.pmd.testframework.SimpleAggregatorTst; @@ -59,7 +62,7 @@ public class DesignRulesTest extends SimpleAggregatorTst { addRule(RULESET, "UseCollectionIsEmpty"); addRule(RULESET, "UseLocaleWithCaseConversions"); addRule(RULESET, "UseNotifyAllInsteadOfNotify"); - addRule(RULESET, "UseSingleton"); + addRule(RULESET, "UseUtilityClass"); addRule(RULESET, "UseVarargs"); } diff --git a/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryRulesTest.java b/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryRulesTest.java index 10e5707d51..8847c14761 100644 --- a/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryRulesTest.java +++ b/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryRulesTest.java @@ -20,7 +20,7 @@ public class UnnecessaryRulesTest extends SimpleAggregatorTst { addRule(RULESET, "UnusedNullCheckInEquals"); addRule(RULESET, "UselessOverridingMethod"); addRule(RULESET, "UselessOperationOnImmutable"); - addRule(RULESET, "UselessParentheses"); + addRule(RULESET, "UselessParentheses"); } public static junit.framework.Test suite() { diff --git a/pmd/src/test/java/net/sourceforge/pmd/renderers/TextRendererTest.java b/pmd/src/test/java/net/sourceforge/pmd/renderers/TextRendererTest.java index 21940e529f..cbff54e6fc 100644 --- a/pmd/src/test/java/net/sourceforge/pmd/renderers/TextRendererTest.java +++ b/pmd/src/test/java/net/sourceforge/pmd/renderers/TextRendererTest.java @@ -12,7 +12,7 @@ public class TextRendererTest extends AbstractRendererTst { @Override public String getExpected() { - return "n/a:1\tmsg" + PMD.EOL; + return "n/a:1:\tmsg" + PMD.EOL; } @Override @@ -22,7 +22,7 @@ public class TextRendererTest extends AbstractRendererTst { @Override public String getExpectedMultiple() { - return "n/a:1\tmsg" + PMD.EOL + "n/a:1\tmsg" + PMD.EOL; + return "n/a:1:\tmsg" + PMD.EOL + "n/a:1:\tmsg" + PMD.EOL; } @Override diff --git a/pmd/src/test/java/net/sourceforge/pmd/renderers/XSLTRendererTest.java b/pmd/src/test/java/net/sourceforge/pmd/renderers/XSLTRendererTest.java new file mode 100644 index 0000000000..5c8d37c484 --- /dev/null +++ b/pmd/src/test/java/net/sourceforge/pmd/renderers/XSLTRendererTest.java @@ -0,0 +1,32 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ +package net.sourceforge.pmd.renderers; + +import junit.framework.Assert; +import net.sourceforge.pmd.Report; +import net.sourceforge.pmd.ReportTest; +import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.RuleViolation; +import net.sourceforge.pmd.lang.java.rule.JavaRuleViolation; + +import org.junit.Test; + +/** + * @author Andreas Dangel + * + */ +public class XSLTRendererTest { + + @Test + public void testDefaultStylesheet() throws Exception { + XSLTRenderer renderer = new XSLTRenderer(); + Report report = new Report(); + RuleViolation rv = new JavaRuleViolation(new ReportTest.FooRule(), new RuleContext(), + ReportTest.getNode(1, 1, "some scope"), + "violation message"); + report.addRuleViolation(rv); + String result = ReportTest.render(renderer, report); + Assert.assertTrue(result.contains("violation message")); + } +} diff --git a/pmd/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases.java b/pmd/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases.java index c598af7f49..7ce8fb40dd 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases.java +++ b/pmd/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases.java @@ -95,4 +95,65 @@ class PmdTestChild extends PmdTestParent { } }); } +} + +/* + * Test cases for bug #1020 Parsing Error + */ +class SimpleBean { + String name; +} + +class SimpleBeanUser { + SimpleBeanUser(SimpleBean o) { + + } + + SimpleBeanUser() { + this(new SimpleBean() {{ + name = "test"; + }}); + } +} + +class SimpleBeanUser2 extends SimpleBeanUser { + SimpleBeanUser2() { + super(new SimpleBean(){{ + name = "test2"; + }}); + } +} + +/* + * Test case for bug #1007 Parse Exception with annotation + */ +class TestParseAnnototation { + void parse() { + for (@SuppressWarnings("unchecked") int i = 0; i < 10; i++) { + } + for (@SuppressWarnings("unchecked") Iterator it = Fachabteilung.values().iterator(); it.hasNext();) { + } + List l = new ArrayList(); + for (@SuppressWarnings("unchecked") String s : l) { + } + } +} + +/* + * Test case for bug #956 PMD Parse Exception + */ +class FooBlock {} +class MyFoo { + MyFoo(FooBlock b) { + } +} +class Foo extends MyFoo { + public Foo() { + super(new FooBlock() { + public Object valueOf(Object object) { + String fish = "salmon"; + return fish; + } + }); + } } \ No newline at end of file diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CloseResource.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CloseResource.xml index 46aba2fc8a..9c2e659b4d 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CloseResource.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CloseResource.xml @@ -181,7 +181,7 @@ public class Foo { - + @@ -247,7 +247,7 @@ public class Foo { ]]> - + @@ -335,5 +335,74 @@ public class StructureFactory { } ]]> - + reinitializeRule="true" + #1011 CloseResource Rule ignores Constructors + 1 + + + + #1011 CloseResource Rule ignores Constructors - closed in finally + 0 + + + + #1011 CloseResource Rule ignores Constructors - not a problem - instance variable + 0 + + + + #1029 No instance level check in the close resource rule + 0 + + + + #947 CloseResource rule fails if field is marked with annotation + 2 + + diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CompareObjectsWithEquals.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CompareObjectsWithEquals.xml index 4c054f4ae0..5b116ae792 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CompareObjectsWithEquals.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CompareObjectsWithEquals.xml @@ -136,5 +136,18 @@ public class Foo { } ]]> - + + #1028 False-positive: Compare objects with equals for Enums + 0 + + diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml index 4524342674..28394d69dc 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml @@ -333,4 +333,16 @@ public class pmd_inc { } ]]> + + #946 ImmutableField false + + 0 + void run(final E entity, final Class> m) throws MyException { + this.counter += 1; + } +} +]]> + diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UseSingleton.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UseUtilityClass.xml similarity index 94% rename from pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UseSingleton.xml rename to pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UseUtilityClass.xml index 670f613b2d..8c508e6d53 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UseSingleton.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UseUtilityClass.xml @@ -2,7 +2,7 @@ 1 1 0 0 1 + + #1058 False positive for VariableNamingConventions + 0 + java 1.7 + (); +} + ]]> + diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/UnnecessaryWrapperObjectCreation.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/UnnecessaryWrapperObjectCreation.xml index e9a67257a4..31d4095110 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/UnnecessaryWrapperObjectCreation.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/UnnecessaryWrapperObjectCreation.xml @@ -53,4 +53,16 @@ public class Bar { } ]]> + + #1057 False positive for UnnecessaryWrapperObjectCreation + 1 + + diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strictexception/xml/SignatureDeclareThrowsException.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strictexception/xml/SignatureDeclareThrowsException.xml index 8c5b3f4014..2d5a63c9e5 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strictexception/xml/SignatureDeclareThrowsException.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strictexception/xml/SignatureDeclareThrowsException.xml @@ -80,4 +80,19 @@ public class FooTest { } ]]> + + #913 SignatureDeclareThrowsException is raised twice + 1 + + diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml index 5dc93cb462..48e8b181b2 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml @@ -177,6 +177,22 @@ public class Test { int dayCount = 4; String description = dayCount + " " + (dayCount == 1 ? oneDay : moreDays); } +} + ]]> + + + #1012 False positive: Useless parentheses. + 0 + diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedFormalParameter.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedFormalParameter.xml index a9396c97cf..9fd0a0b53a 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedFormalParameter.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedFormalParameter.xml @@ -234,4 +234,14 @@ class Foo { ]]> + + #878 don't flag abstract methods even if checkall property is set when checking an abstract class + true + 0 + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000..fd08f60f0f --- /dev/null +++ b/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + net.sourceforge.pmd + pmd-aggregate + 1.0.0-SNAPSHOT + + pom + + PMD Aggregate Project + + http://pmd.sourceforge.net/ + + + pmd + + diff --git a/website/.htaccess b/website/.htaccess index 3b4b1b831e..6440e63768 100644 --- a/website/.htaccess +++ b/website/.htaccess @@ -10,3 +10,8 @@ RewriteRule .* - [E=PMD:pmd-5.0.1] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond /home/project-web/pmd/htdocs/%{ENV:PMD}%{REQUEST_URI} -f RewriteRule .* /%{ENV:PMD}%{REQUEST_URI} [L,R] + +# rewrite any remaining request to pmd-4.3.0 for backwards compatibility +# as the old versions link to a non-versioned rule description URLs. +RewriteCond /home/project-web/pmd/htdocs/pmd-4.3.0%{REQUEST_URI} -f +RewriteRule .* /pmd-4.3.0%{REQUEST_URI} [L,R]