Compare commits

..
Author SHA1 Message Date
Andreas Dangel e1cc5d44b5 Prepare release pmd-eclipse-plugin 4.0.2.v20131031-1124 2013-10-31 12:35:23 +01:00
3674 changed files with 201940 additions and 128780 deletions

No files matched your search

-12
View File
@@ -1,12 +0,0 @@
target/
bin/
.project
.classpath
.checkstyle
.pmd
.ruleset
.settings/
*.iml
.idea
*.patch
*/src/site/site.xml
-21
View File
@@ -1,21 +0,0 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>${env.CI_DEPLOY_USERNAME}</username>
<password>${env.CI_DEPLOY_PASSWORD}</password>
</server>
</servers>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
-29
View File
@@ -1,29 +0,0 @@
language: java
before_script:
- SHOULD_DEPLOY=no
- '[ "${TRAVIS_SECURE_ENV_VARS}" = "true" ] && [ "${TRAVIS_PULL_REQUEST}" = "false" ] && SHOULD_DEPLOY=yes || ( [ "${SHOULD_DEPLOY}" != "yes" ] && echo "Skipping Deploy" )'
- export SHOULD_DEPLOY
matrix:
include:
- jdk: oraclejdk7
script:
- '[ "${SHOULD_DEPLOY}" = "yes" ] && mvn test deploy --settings .travis-settings.xml || ( [ "${SHOULD_DEPLOY}" != "yes" ] && echo "Skipping Deploy" )'
- '[ "${SHOULD_DEPLOY}" = "yes" ] || mvn test'
- jdk: oraclejdk8
script: mvn test
branches:
except:
- /^pmd_releases\/\d/
notifications:
email:
recipients:
- adangel@users.sourceforge.net
on_success: always
on_failure: always
cache:
directories:
- "$HOME/.m2"
env:
global:
- secure: KBEuB6U1p5RQXSYe157AwydFr/zpXQPA0IChVCgZV+X1mMyy9ZtrjH1J1AXuviseDDXDbaT25sRnsvpl82rfRw2xOkMGXHy4N95/ylTSr8DjHxTao71BhXsvFycNobFva5y2EGNWqDvpS8I2oSZo7Qk4la3yep3rcJQvcy6RDbbhpDTbL1QMFyadunIBm0WtqbunrMqtjSqaoPsXz8TiQuxHvX4vEXzVbaxV1QQt79Vi+daa6wAV3mRQAugnx+UffsC8JqMxgm06usWeJgCJzxgm8E7clZCLmf53B2TL8dK6bIYbqyvOY3uFxitsTG0d8Z0GOJwXBgZNgbniTRO8ZJSty5eZP8LBybbjVLSL25DNTWtCjADUL/uySnXIEidlMt2N/3QmH7zrGAfAk/tIwKpdRca2GLLydeXf6PSkiahnPEkIY/QupcsOLELhdifpdOjb8QW1OenA+vUbNM9dccLwKnX6Fj9cu4VQG601AcYDr2eyhq8WYkr3wYdw/6KdUa3hmplowTBs+qguppP+eOSgGuEsy38KLtqnvm6WlHy6tcLmcVYKG3DmR1b7TWXsOXC6/VMH8BHBkvsF1QdRg9+Cgx07vX3Hw7roPiYzmaO9Ajs20ATsUfRskMuWCTeTSK5pN8X27veRCZlhFjeKQMDdmfVwzpAfRgKsl3TEn1I=
- secure: U1DfAv6acUUWe+dao/ZSDUX64JRadNJY16rITsdrM4ZNAJSuXpEY3p/LWcYjN7D49YmyutbXH9+L3KKQUQGrGXj9QTarfYvd8ZsKt4FK8yv7AFy+RQNIbAjNEHBzHx15p+srMheTaetl7aLwY0qhF+D/RtGapxHKyY4dBHrb0lp8VGyiCiL7Aop8GGskosi1mtirPBp/BStPZ2bEyxG0QzU5SsVWkJWwV9aWLPVAR/n7Xgx/6Gjl6Fed2c/WSrWi4vchm3Ny8pfTweOax3PGYYjBVxIfuX0mqmwuJsY7gNfXCfN3dPiPKGJPFy1pC+LGyGkklO5ReKFLd4O1ME6fU0dlIGfD6n+Q4H6/w9FHXegcKTfWIJm/MFa6vA/tJM5R6zJQuiTQJboHm/UmS/iQj76z0p6sK15Xp5vFId+/dHKqa8xY+Bt6HiXy6z401HOc8QcYBAf7TqhqUt/ZE7HN4be46uR90KmzIrWz6wEoDW7HfwQ9ZMbs55zoOXrvekyE9/gXskypO0p2JT3Y0vlvO27KQvIrSwI480kOVOrlyrYA+LZqlcKaayOuCuZh4lITQUYinUoZZict5joYthH+Cyh2zovoBpxsntDJdMnaZNLtSC7hlhpbMBYaT2y1O6vZH5Yix0mxuDvs/x6ogP5CNBeUYlXhaL+g4GnwKyr0ZA0=
-405
View File
File diff suppressed because it is too large. Load diff
-12
View File
@@ -1,12 +0,0 @@
PMD
This product is licensed under a BSD-style license;
for more info see http://pmd.sourceforge.net/license.html or LICENSE
Part of this product (mostly the package net.sourceforge.pmd.lang.vm)
is licensed under the Apache License, Version 2.0;
for more info see http://www.apache.org/licenses/LICENSE-2.0 or LICENSE
Part of this product (part of pmd-scala)
is licensed under the GNU Lesser General Public License, Version 3 or later
for more info see http://www.gnu.org/licenses/lgpl.txt or LICENSE
+13 -31
View File
@@ -1,45 +1,27 @@
# PMD
[![PMD - Don't shoot the messenger][PMDLogo]][website]
[![Build Status](https://travis-ci.org/pmd/pmd.svg?branch=master)](https://travis-ci.org/pmd/pmd)
## About
PMD
===
About
-----
PMD is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks,
unnecessary object creation, and so forth. It supports Java, JavaScript, XML, XSL.
Additionally it includes CPD, the copy-paste-detector. CPD finds duplicated code in
Java, C, C++, C#, PHP, Ruby, Fortran, JavaScript.
## Source
Source
------
Our latest source of PMD can be found on [GitHub]. Fork us!
The current status of this repo can be seen at [BuildHive].
### How to build PMD?
Simply use maven in the top-level directory:
mvn clean package
This will create the zip files in the directory `pmd-dist/target`:
cd pmd-dist/target
ls *.zip
That's all !
### Bug Reports
We are using Sourceforge for bug tracking. Please file your bugs at <https://sourceforge.net/p/pmd/bugs/>.
### Pull Requests
Pull requests are always welcome: <https://github.com/pmd/pmd/pulls>
## News and Website
News and Website
----------------
More information can be found on our [Website] and on [SourceForge].
[PMDLogo]: http://pmd.sourceforge.net/pmd_logo.png
[GitHub]: https://github.com/pmd/pmd
[Website]: https://pmd.github.io
[BuildHive]: https://buildhive.cloudbees.com/job/pmd/
[Website]: http://pmd.sourceforge.net
[SourceForge]: https://sourceforge.net/projects/pmd/
@@ -0,0 +1,41 @@
package net.sourceforge.pmd.util.viewer;
import net.sourceforge.pmd.util.viewer.gui.MainFrame;
/**
* viewer's starter
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class Viewer {
/**
* starts the viewer
*
* @param args arguments
*/
public static void main(String[] args) {
new MainFrame();
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:41 tomcopeland
* Initial revision
*
* Revision 1.2 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,147 @@
package net.sourceforge.pmd.util.viewer.gui;
import net.sourceforge.pmd.ast.Node;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.util.viewer.gui.menu.ASTNodePopupMenu;
import net.sourceforge.pmd.util.viewer.model.ASTModel;
import net.sourceforge.pmd.util.viewer.model.ViewerModel;
import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
import net.sourceforge.pmd.util.viewer.util.NLS;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.LinkedList;
/**
* tree panel GUI
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class ASTPanel
extends JPanel
implements ViewerModelListener, TreeSelectionListener {
private ViewerModel model;
private JTree tree;
/**
* constructs the panel
*
* @param model model to attach the panel to
*/
public ASTPanel(ViewerModel model) {
this.model = model;
init();
}
private void init() {
model.addViewerModelListener(this);
setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), NLS.nls("AST.PANEL.TITLE")));
setLayout(new BorderLayout());
tree = new JTree((TreeNode) null);
tree.addTreeSelectionListener(this);
tree.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
TreePath path =
tree.getClosestPathForLocation(e.getX(), e.getY());
tree.setSelectionPath(path);
JPopupMenu menu =
new ASTNodePopupMenu(model, (SimpleNode) path.getLastPathComponent());
menu.show(tree, e.getX(), e.getY());
}
}
});
add(new JScrollPane(tree), BorderLayout.CENTER);
}
/**
* @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
*/
public void viewerModelChanged(ViewerModelEvent e) {
switch (e.getReason()) {
case ViewerModelEvent.CODE_RECOMPILED:
tree.setModel(new ASTModel(model.getRootNode()));
break;
case ViewerModelEvent.NODE_SELECTED:
if (e.getSource() != this) {
LinkedList list = new LinkedList();
for (
Node node = (Node) e.getParameter(); node != null;
node = node.jjtGetParent())
list.addFirst(node);
TreePath path = new TreePath(list.toArray());
tree.setSelectionPath(path);
tree.scrollPathToVisible(path);
}
break;
}
}
/**
* @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
*/
public void valueChanged(TreeSelectionEvent e) {
model.selectNode((SimpleNode) e.getNewLeadSelectionPath().getLastPathComponent(), this);
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.5 2005/02/16 15:46:05 mikkey
* javadoc fixes
*
* Revision 1.4 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.3 2004/04/15 18:21:58 tomcopeland
* Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.3 2003/09/24 00:40:35 bgr
* evaluation results browsing added
*
* Revision 1.2 2003/09/23 07:52:16 bgr
* menus added
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,35 @@
package net.sourceforge.pmd.util.viewer.gui;
/**
* contains action command constants
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public interface ActionCommands {
String COMPILE_ACTION = "Compile";
String EVALUATE_ACTION = "Evaluate";
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.3 2004/12/22 20:52:12 tomcopeland
* Fixing some stuff PMD found
*
* Revision 1.2 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,105 @@
package net.sourceforge.pmd.util.viewer.gui;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.util.viewer.model.ViewerModel;
import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.BorderLayout;
import java.util.Vector;
/**
* A panel showing XPath expression evaluation results
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class EvaluationResultsPanel
extends JPanel
implements ViewerModelListener {
private ViewerModel model;
private JList list;
/**
* constructs the panel
*
* @param model model to refer to
*/
public EvaluationResultsPanel(ViewerModel model) {
super(new BorderLayout());
this.model = model;
init();
}
private void init() {
model.addViewerModelListener(this);
list = new JList();
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (list.getSelectedValue() != null) {
model.selectNode((SimpleNode) list.getSelectedValue(), EvaluationResultsPanel.this);
}
}
});
add(new JScrollPane(list), BorderLayout.CENTER);
}
/**
* @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
*/
public void viewerModelChanged(ViewerModelEvent e) {
switch (e.getReason()) {
case ViewerModelEvent.PATH_EXPRESSION_EVALUATED:
if (e.getSource() != this) {
list.setListData(new Vector(model.getLastEvaluationResults()));
}
break;
case ViewerModelEvent.CODE_RECOMPILED:
list.setListData(new Vector(0));
break;
}
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.5 2005/02/16 15:46:34 mikkey
* javadoc fixes
*
* Revision 1.4 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.3 2004/04/15 18:21:58 tomcopeland
* Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/24 00:40:35 bgr
* evaluation results browsing added
*
*/
@@ -0,0 +1,172 @@
package net.sourceforge.pmd.util.viewer.gui;
import net.sourceforge.pmd.ast.ParseException;
import net.sourceforge.pmd.util.viewer.model.ViewerModel;
import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
import net.sourceforge.pmd.util.viewer.util.NLS;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* viewer's main frame
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class MainFrame
extends JFrame
implements ActionListener, ActionCommands, ViewerModelListener {
private ViewerModel model;
private SourceCodePanel sourcePanel;
private ASTPanel astPanel;
private XPathPanel xPathPanel;
private JButton compileBtn;
private JButton evalBtn;
private JLabel statusLbl;
/**
* constructs and shows the frame
*/
public MainFrame() {
super(NLS.nls("MAIN.FRAME.TITLE"));
init();
}
private void init() {
model = new ViewerModel();
model.addViewerModelListener(this);
sourcePanel = new SourceCodePanel(model);
astPanel = new ASTPanel(model);
xPathPanel = new XPathPanel(model);
getContentPane().setLayout(new BorderLayout());
JSplitPane editingPane =
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sourcePanel, astPanel);
editingPane.setResizeWeight(0.5d);
JPanel interactionsPane = new JPanel(new BorderLayout());
interactionsPane.add(xPathPanel, BorderLayout.SOUTH);
interactionsPane.add(editingPane, BorderLayout.CENTER);
getContentPane().add(interactionsPane, BorderLayout.CENTER);
compileBtn = new JButton(NLS.nls("MAIN.FRAME.COMPILE_BUTTON.TITLE"));
compileBtn.setActionCommand(COMPILE_ACTION);
compileBtn.addActionListener(this);
evalBtn = new JButton(NLS.nls("MAIN.FRAME.EVALUATE_BUTTON.TITLE"));
evalBtn.setActionCommand(EVALUATE_ACTION);
evalBtn.addActionListener(this);
evalBtn.setEnabled(false);
statusLbl = new JLabel();
statusLbl.setHorizontalAlignment(SwingConstants.RIGHT);
JPanel btnPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
btnPane.add(compileBtn);
btnPane.add(evalBtn);
btnPane.add(statusLbl);
getContentPane().add(btnPane, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
pack();
setSize(800, 600);
setVisible(true);
}
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
long t0, t1;
if (command.equals(COMPILE_ACTION)) {
try {
t0 = System.currentTimeMillis();
model.commitSource(sourcePanel.getSourceCode());
t1 = System.currentTimeMillis();
setStatus(NLS.nls("MAIN.FRAME.COMPILATION.TOOK")+ " "+(t1-t0)+" ms");
} catch (ParseException exc) {
setStatus(NLS.nls("MAIN.FRAME.COMPILATION.PROBLEM")+ " "+exc.toString());
new ParseExceptionHandler(this, exc);
}
} else if (command.equals(EVALUATE_ACTION)) {
try {
t0 = System.currentTimeMillis();
model.evaluateXPathExpression(xPathPanel.getXPathExpression(), this);
t1 = System.currentTimeMillis();
setStatus(NLS.nls("MAIN.FRAME.EVALUATION.TOOK")+ " "+(t1-t0)+" ms");
} catch (Exception exc) {
setStatus(NLS.nls("MAIN.FRAME.EVALUATION.PROBLEM")+ " "+exc.toString());
new ParseExceptionHandler(this, exc);
}
}
}
/**
* Sets the status bar message
* @param string the new status, the empty string will be set if the value is <code>null</code>
*/
private void setStatus(String string) {
if (string == null)
string = "";
statusLbl.setText(string);
}
/**
* @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
*/
public void viewerModelChanged(ViewerModelEvent e) {
evalBtn.setEnabled(model.hasCompiledTree());
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.6 2005/02/16 15:47:01 mikkey
* javadoc fixes
*
* Revision 1.5 2004/12/13 14:46:11 tomcopeland
* Applied, thanks Miguel!
*
* Revision 1.4 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.3 2004/04/15 18:21:58 tomcopeland
* Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.2 2003/09/24 00:40:35 bgr
* evaluation results browsing added
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,112 @@
package net.sourceforge.pmd.util.viewer.gui;
import net.sourceforge.pmd.util.viewer.util.NLS;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* handles parsing exceptions
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class ParseExceptionHandler
extends JDialog
implements ActionListener {
private Exception exc;
private JTextArea errorArea;
private JButton okBtn;
/**
* creates the dialog
*
* @param parent dialog's parent
* @param exc exception to be handled
*/
public ParseExceptionHandler(JFrame parent, Exception exc) {
super(parent, NLS.nls("COMPILE_ERROR.DIALOG.TITLE"), true);
this.exc = exc;
init();
}
private void init() {
errorArea = new JTextArea();
errorArea.setEditable(false);
errorArea.setText(exc.getMessage() + "\n");
getContentPane().setLayout(new BorderLayout());
JPanel messagePanel = new JPanel(new BorderLayout());
messagePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),
BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
NLS.nls("COMPILE_ERROR.PANEL.TITLE"))));
messagePanel.add(new JScrollPane(errorArea), BorderLayout.CENTER);
getContentPane().add(messagePanel, BorderLayout.CENTER);
JPanel btnPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
okBtn = new JButton(NLS.nls("COMPILE_ERROR.OK_BUTTON.CAPTION"));
okBtn.addActionListener(this);
btnPane.add(okBtn);
getRootPane().setDefaultButton(okBtn);
getContentPane().add(btnPane, BorderLayout.SOUTH);
pack();
setLocationRelativeTo(getParent());
setVisible(true);
}
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() == okBtn) {
dispose();
}
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.4 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.3 2004/04/15 18:21:58 tomcopeland
* Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.2 2003/09/24 00:40:35 bgr
* evaluation results browsing added
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,119 @@
package net.sourceforge.pmd.util.viewer.gui;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.util.viewer.model.ViewerModel;
import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
import net.sourceforge.pmd.util.viewer.util.NLS;
import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import java.awt.BorderLayout;
import java.awt.Color;
/**
* source code panel
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class SourceCodePanel
extends JPanel
implements ViewerModelListener {
private ViewerModel model;
private JTextArea sourceCodeArea;
public SourceCodePanel(ViewerModel model) {
this.model = model;
init();
}
private void init() {
model.addViewerModelListener(this);
setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), NLS.nls("SOURCE.PANEL.TITLE")));
setLayout(new BorderLayout());
sourceCodeArea = new JTextArea();
add(new JScrollPane(sourceCodeArea), BorderLayout.CENTER);
}
/**
* retrieves the string representation of the source code
*
* @return source code's string representation
*/
public String getSourceCode() {
return sourceCodeArea.getText();
}
/**
* @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
*/
public void viewerModelChanged(ViewerModelEvent e) {
if (e.getReason() == ViewerModelEvent.NODE_SELECTED) {
final SimpleNode node = (SimpleNode) e.getParameter();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
sourceCodeArea.getHighlighter().removeAllHighlights();
if (node == null) {
return;
}
int startOffset =
(sourceCodeArea.getLineStartOffset(node.getBeginLine() - 1) +
node.getBeginColumn()) - 1;
int end =
(sourceCodeArea.getLineStartOffset(node.getEndLine() - 1) +
node.getEndColumn());
sourceCodeArea.getHighlighter().addHighlight(startOffset, end,
new DefaultHighlighter.DefaultHighlightPainter(new Color(79, 237, 111)));
sourceCodeArea.moveCaretPosition(startOffset);
} catch (BadLocationException exc) {
throw new IllegalStateException(exc.getMessage());
}
}
});
}
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.5 2005/02/16 15:47:27 mikkey
* javadoc fixes
*
* Revision 1.4 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.3 2004/04/15 18:21:58 tomcopeland
* Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,115 @@
package net.sourceforge.pmd.util.viewer.gui;
import net.sourceforge.pmd.util.viewer.model.ViewerModel;
import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
import net.sourceforge.pmd.util.viewer.util.NLS;
import javax.swing.*;
import java.awt.Dimension;
/**
* Panel for the XPath entry and editing
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class XPathPanel
extends JTabbedPane
implements ViewerModelListener {
private ViewerModel model;
private JTextArea xPathArea;
/**
* Constructs the panel
*
* @param model model to refer to
*/
public XPathPanel(ViewerModel model) {
super(JTabbedPane.BOTTOM);
this.model = model;
init();
}
private void init() {
model.addViewerModelListener(this);
xPathArea = new JTextArea();
setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), NLS.nls("XPATH.PANEL.TITLE")));
add(new JScrollPane(xPathArea), NLS.nls("XPATH.PANEL.EXPRESSION"));
add(new EvaluationResultsPanel(model), NLS.nls("XPATH.PANEL.RESULTS"));
setPreferredSize(new Dimension(-1, 200));
}
/**
* retrieves the XPath expression typed into the text area
*
* @return XPath expression
*/
public String getXPathExpression() {
return xPathArea.getText();
}
/**
* @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
*/
public void viewerModelChanged(ViewerModelEvent e) {
switch (e.getReason()) {
case ViewerModelEvent.PATH_EXPRESSION_APPENDED:
if (e.getSource() != this) {
xPathArea.append((String) e.getParameter());
}
setSelectedIndex(0);
break;
case ViewerModelEvent.CODE_RECOMPILED:
setSelectedIndex(0);
break;
}
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.5 2005/02/16 15:47:48 mikkey
* javadoc fixes
*
* Revision 1.4 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.3 2004/04/15 18:21:58 tomcopeland
* Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.3 2003/09/24 00:40:35 bgr
* evaluation results browsing added
*
* Revision 1.2 2003/09/23 07:52:16 bgr
* menus added
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,63 @@
package net.sourceforge.pmd.util.viewer.gui.menu;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.util.viewer.model.ViewerModel;
import javax.swing.*;
/**
* context sensetive menu for the AST Panel
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class ASTNodePopupMenu
extends JPopupMenu {
private ViewerModel model;
private SimpleNode node;
public ASTNodePopupMenu(ViewerModel model, SimpleNode node) {
this.model = model;
this.node = node;
init();
}
private void init() {
add(new SimpleNodeSubMenu(model, node));
addSeparator();
add(new AttributesSubMenu(model, node));
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:43 tomcopeland
* Initial revision
*
* Revision 1.5 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.4 2004/04/15 18:21:58 tomcopeland
* Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
*
* Revision 1.3 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.2 2003/09/23 20:34:33 tomcopeland
* Fixed some stuff PMD found
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/23 07:52:16 bgr
* menus added
*
*/
@@ -0,0 +1,73 @@
package net.sourceforge.pmd.util.viewer.gui.menu;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.jaxen.Attribute;
import net.sourceforge.pmd.jaxen.AttributeAxisIterator;
import net.sourceforge.pmd.util.viewer.model.AttributeToolkit;
import net.sourceforge.pmd.util.viewer.model.ViewerModel;
import net.sourceforge.pmd.util.viewer.util.NLS;
import javax.swing.*;
import java.text.MessageFormat;
/**
* contains menu items for the predicate creation
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class AttributesSubMenu
extends JMenu {
private ViewerModel model;
private SimpleNode node;
public AttributesSubMenu(ViewerModel model, SimpleNode node) {
super(MessageFormat.format(NLS.nls("AST.MENU.ATTRIBUTES"), new Object[]{node.toString()}));
this.model = model;
this.node = node;
init();
}
private void init() {
AttributeAxisIterator i = new AttributeAxisIterator(node);
while (i.hasNext()) {
Attribute attribute = (Attribute) i.next();
add(new XPathFragmentAddingItem(attribute.getName() + " = " + attribute.getValue(), model,
AttributeToolkit.constructPredicate(attribute)));
}
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:43 tomcopeland
* Initial revision
*
* Revision 1.5 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.4 2004/04/15 18:21:58 tomcopeland
* Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
*
* Revision 1.3 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.2 2003/09/23 20:34:34 tomcopeland
* Fixed some stuff PMD found
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/23 07:52:16 bgr
* menus added
*
*/
@@ -0,0 +1,76 @@
package net.sourceforge.pmd.util.viewer.gui.menu;
import net.sourceforge.pmd.ast.Node;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.util.viewer.model.ViewerModel;
import net.sourceforge.pmd.util.viewer.util.NLS;
import javax.swing.*;
import java.text.MessageFormat;
/**
* submenu for the simple node itself
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class SimpleNodeSubMenu
extends JMenu {
private ViewerModel model;
private SimpleNode node;
/**
* constructs the submenu
*
* @param model model to which the actions will be forwarded
* @param node menu's owner
*/
public SimpleNodeSubMenu(ViewerModel model, SimpleNode node) {
super(MessageFormat.format(NLS.nls("AST.MENU.NODE.TITLE"), new Object[]{node.toString()}));
this.model = model;
this.node = node;
init();
}
private void init() {
StringBuffer buf = new StringBuffer(200);
for (Node temp = node; temp != null; temp = temp.jjtGetParent()) {
buf.insert(0, "/" + temp.toString());
}
add(new XPathFragmentAddingItem(NLS.nls("AST.MENU.NODE.ADD_ABSOLUTE_PATH"), model, buf.toString()));
add(new XPathFragmentAddingItem(NLS.nls("AST.MENU.NODE.ADD_ALLDESCENDANTS"), model,
"//" + node.toString()));
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:43 tomcopeland
* Initial revision
*
* Revision 1.4 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.3 2004/04/15 18:21:58 tomcopeland
* Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/23 07:52:16 bgr
* menus added
*
*/
@@ -0,0 +1,70 @@
package net.sourceforge.pmd.util.viewer.gui.menu;
import net.sourceforge.pmd.util.viewer.model.ViewerModel;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* adds the given path fragment to the XPath expression upon action
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class XPathFragmentAddingItem
extends JMenuItem
implements ActionListener {
private ViewerModel model;
private String fragment;
/**
* constructs the item
*
* @param caption menu item's caption
* @param model model to refer to
* @param fragment XPath expression fragment to be added upon action
*/
public XPathFragmentAddingItem(String caption, ViewerModel model, String fragment) {
super(caption);
this.model = model;
this.fragment = fragment;
addActionListener(this);
}
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
model.appendToXPathExpression(fragment, this);
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.4 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.3 2004/04/15 18:21:58 tomcopeland
* Cleaned up imports with new version of IDEA; fixed some deprecated Ant junx
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/23 07:52:16 bgr
* menus added
*
*/
@@ -0,0 +1,125 @@
package net.sourceforge.pmd.util.viewer.model;
import net.sourceforge.pmd.ast.SimpleNode;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import java.util.Vector;
/**
* Model for the AST Panel Tree component
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class ASTModel
implements TreeModel {
private SimpleNode root;
private Vector listeners = new Vector(1);
/**
* creates the tree model
*
* @param root tree's root
*/
public ASTModel(SimpleNode root) {
this.root = root;
}
/**
* @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int)
*/
public Object getChild(Object parent, int index) {
return ((SimpleNode) parent).jjtGetChild(index);
}
/**
* @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object)
*/
public int getChildCount(Object parent) {
return ((SimpleNode) parent).jjtGetNumChildren();
}
/**
* @see javax.swing.tree.TreeModel#getIndexOfChild(java.lang.Object,
* java.lang.Object)
*/
public int getIndexOfChild(Object parent, Object child) {
SimpleNode node = ((SimpleNode) parent);
for (int i = 0; i < node.jjtGetNumChildren(); i++)
if (node.jjtGetChild(i).equals(child)) {
return i;
}
return -1;
}
/**
* @see javax.swing.tree.TreeModel#isLeaf(java.lang.Object)
*/
public boolean isLeaf(Object node) {
return ((SimpleNode) node).jjtGetNumChildren() == 0;
}
/**
* @see javax.swing.tree.TreeModel#getRoot()
*/
public Object getRoot() {
return root;
}
/**
* @see javax.swing.tree.TreeModel#valueForPathChanged(javax.swing.tree.TreePath,
* java.lang.Object)
*/
public void valueForPathChanged(TreePath path, Object newValue) {
throw new UnsupportedOperationException();
}
/**
* @see javax.swing.tree.TreeModel#addTreeModelListener(javax.swing.event.TreeModelListener)
*/
public void addTreeModelListener(TreeModelListener l) {
listeners.add(l);
}
/**
* @see javax.swing.tree.TreeModel#removeTreeModelListener(javax.swing.event.TreeModelListener)
*/
public void removeTreeModelListener(TreeModelListener l) {
listeners.remove(l);
}
protected void fireTreeModelEvent(TreeModelEvent e) {
for (int i = 0; i < listeners.size(); i++) {
((TreeModelListener) listeners.elementAt(i)).treeNodesChanged(e);
}
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.3 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/24 00:40:35 bgr
* evaluation results browsing added
*
*/
@@ -0,0 +1,53 @@
package net.sourceforge.pmd.util.viewer.model;
import net.sourceforge.pmd.jaxen.Attribute;
/**
* A toolkit for vaious attribute translations
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class AttributeToolkit {
/**
* formats a value for it's usage in XPath expressions
*
* @param attribute atribute which value should be formatted
* @return formmated value
*/
public static String formatValueForXPath(Attribute attribute) {
return "'" + attribute.getValue() + "'";
}
/**
* constructs a predicate from the given attribute
*
* @param attribute attribute to be formatted as predicate
* @return predicate
*/
public static String constructPredicate(Attribute attribute) {
return "[@" + attribute.getName() + "=" +
formatValueForXPath(attribute) + "]";
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.2 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/23 07:52:16 bgr
* menus added
*
*/
@@ -0,0 +1,142 @@
package net.sourceforge.pmd.util.viewer.model;
import net.sourceforge.pmd.ast.SimpleNode;
import javax.swing.tree.TreeNode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
/**
* provides the adapter for the tree model
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class SimpleNodeTreeNodeAdapter
implements TreeNode {
private SimpleNode node;
private List children;
private SimpleNodeTreeNodeAdapter parent;
/**
* constructs the node
*
* @param node underlying AST's node
*/
public SimpleNodeTreeNodeAdapter(SimpleNodeTreeNodeAdapter parent, SimpleNode node) {
this.parent = parent;
this.node = node;
}
/**
* retrieves the underlying node
*
* @return AST node
*/
public SimpleNode getSimpleNode() {
return node;
}
/**
* @see javax.swing.tree.TreeNode#getChildAt(int)
*/
public TreeNode getChildAt(int childIndex) {
checkChildren();
return (TreeNode) children.get(childIndex);
}
/**
* @see javax.swing.tree.TreeNode#getChildCount()
*/
public int getChildCount() {
checkChildren();
return children.size();
}
/**
* @see javax.swing.tree.TreeNode#getParent()
*/
public TreeNode getParent() {
return parent;
}
/**
* @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
*/
public int getIndex(TreeNode node) {
checkChildren();
return children.indexOf(node);
}
/**
* @see javax.swing.tree.TreeNode#getAllowsChildren()
*/
public boolean getAllowsChildren() {
return true;
}
/**
* @see javax.swing.tree.TreeNode#isLeaf()
*/
public boolean isLeaf() {
checkChildren();
return children.size() == 0;
}
/**
* @see javax.swing.tree.TreeNode#children()
*/
public Enumeration children() {
return Collections.enumeration(children);
}
/**
* checks the children and creates them if neccessary
*/
private void checkChildren() {
if (children == null) {
children = new ArrayList(node.jjtGetNumChildren());
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
children.add(new SimpleNodeTreeNodeAdapter(this, (SimpleNode) node.jjtGetChild(i)));
}
}
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return node.toString();
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:41 tomcopeland
* Initial revision
*
* Revision 1.3 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,180 @@
package net.sourceforge.pmd.util.viewer.model;
import net.sourceforge.pmd.TargetJDK1_4;
import net.sourceforge.pmd.ast.ASTCompilationUnit;
import net.sourceforge.pmd.ast.ParseException;
import net.sourceforge.pmd.ast.SimpleNode;
import net.sourceforge.pmd.jaxen.DocumentNavigator;
import org.jaxen.BaseXPath;
import org.jaxen.JaxenException;
import org.jaxen.XPath;
import java.io.StringReader;
import java.util.List;
import java.util.Vector;
/**
* The model for the viewer gui
* <p/>
* <p/>
* This is the model part of MVC
* </p>
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class ViewerModel {
private Vector listeners;
private SimpleNode rootNode;
private List evaluationResults;
/**
* constructs the model
*/
public ViewerModel() {
listeners = new Vector(5);
}
/**
* Retrieves AST's root node
*
* @return AST's root node
*/
public SimpleNode getRootNode() {
return rootNode;
}
/**
* commits source code to the model.
* <p/>
* <p/>
* all existing source will be replaced
* </p>
*
* @param source source to be commited
*/
public void commitSource(String source) {
ASTCompilationUnit compilationUnit = new TargetJDK1_4().createParser(new StringReader(source)).CompilationUnit();
rootNode = compilationUnit;
fireViewerModelEvent(new ViewerModelEvent(this, ViewerModelEvent.CODE_RECOMPILED));
}
/**
* determines wheteher the model has a compiled tree at it's disposal
*
* @return true if there is an AST, false otherwise
*/
public boolean hasCompiledTree() {
return rootNode != null;
}
/**
* evaluates the given XPath expression against the current tree
*
* @param xPath XPath expression to be evaluated
* @param evaluator object which requests the evaluation
*/
public void evaluateXPathExpression(String xPath, Object evaluator)
throws ParseException, JaxenException {
XPath xpath = new BaseXPath(xPath, new DocumentNavigator());
evaluationResults = xpath.selectNodes(rootNode);
fireViewerModelEvent(new ViewerModelEvent(evaluator, ViewerModelEvent.PATH_EXPRESSION_EVALUATED));
}
/**
* retrieves the results of last evaluation
*
* @return a list containing the nodes selected by the last XPath expression
* evaluation
*/
public List getLastEvaluationResults() {
return evaluationResults;
}
/**
* selects the given node in the AST
*
* @param node node to be selected
* @param selector object which requests the selection
*/
public void selectNode(SimpleNode node, Object selector) {
fireViewerModelEvent(new ViewerModelEvent(selector, ViewerModelEvent.NODE_SELECTED, node));
}
/**
* appends the given fragment to the XPath expression
*
* @param pathFragment fragment to be added
* @param appender object that is trying to append the fragment
*/
public void appendToXPathExpression(String pathFragment, Object appender) {
fireViewerModelEvent(new ViewerModelEvent(appender, ViewerModelEvent.PATH_EXPRESSION_APPENDED, pathFragment));
}
/**
* adds a listener to the model
*
* @param l listener to be added
*/
public void addViewerModelListener(ViewerModelListener l) {
listeners.add(l);
}
/**
* removes the lisetener from the model
*
* @param l listener to be removed
*/
public void removeViewerModelListener(ViewerModelListener l) {
listeners.remove(l);
}
/**
* notifes all listener of a change in the model
*
* @param e change's reason
*/
protected void fireViewerModelEvent(ViewerModelEvent e) {
for (int i = 0; i < listeners.size(); i++) {
((ViewerModelListener) listeners.elementAt(i)).viewerModelChanged(e);
}
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.5 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.4 2004/04/12 17:35:09 tomcopeland
* Cleaned up imports
*
* Revision 1.3 2004/04/12 17:23:29 tomcopeland
* Moving all explicit JavaParser creations over to a factory-ish sort of thing. This makes the version of the parser explicit rather than assumed.
*
* Revision 1.2 2003/09/23 20:51:06 tomcopeland
* Cleaned up imports
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.3 2003/09/24 00:40:35 bgr
* evaluation results browsing added
*
* Revision 1.2 2003/09/23 07:52:16 bgr
* menus added
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,112 @@
package net.sourceforge.pmd.util.viewer.model;
/**
* The event which will be sent every time the model changes
* <p/>
* <p/>
* Note: the instances will be immutable
* </p>
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class ViewerModelEvent {
/**
* reason in the case of code recompilation
*/
public static final int CODE_RECOMPILED = 1;
/**
* reason in the case of node selection
*/
public static final int NODE_SELECTED = 2;
/**
* reason in the case of path extension
*/
public static final int PATH_EXPRESSION_APPENDED = 3;
/**
* reason in the case of path expression evaluation
*/
public static final int PATH_EXPRESSION_EVALUATED = 4;
private Object source;
private int reason;
private Object parameter;
/**
* Creates an event
*
* @param source event's source
* @param reason event's reason
*/
public ViewerModelEvent(Object source, int reason) {
this(source, reason, null);
}
/**
* Creates an event
*
* @param source event's source
* @param reason event's reason
* @param parameter parameter object
*/
public ViewerModelEvent(Object source, int reason, Object parameter) {
this.source = source;
this.reason = reason;
this.parameter = parameter;
}
/**
* retrieves the reason for event's occurance
*
* @return event's reason
*/
public int getReason() {
return reason;
}
/**
* retrieves the object which caused the event
*
* @return object that casused the event
*/
public Object getSource() {
return source;
}
/**
* retrieves event's parameter
*
* @return event's parameter
*/
public Object getParameter() {
return parameter;
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.2 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.3 2003/09/24 00:40:35 bgr
* evaluation results browsing added
*
* Revision 1.2 2003/09/23 07:52:16 bgr
* menus added
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,39 @@
package net.sourceforge.pmd.util.viewer.model;
/**
* identiefie a listener of the ViewerModel
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public interface ViewerModelListener {
/**
* DOCUMENT ME!
*
* @param e DOCUMENT ME!
*/
void viewerModelChanged(ViewerModelEvent e);
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.3 2004/12/22 20:52:12 tomcopeland
* Fixing some stuff PMD found
*
* Revision 1.2 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
@@ -0,0 +1,34 @@
##########################################################################
# english string translations for the viewer
#
##########################################################################
# Main Frame
MAIN.FRAME.TITLE = AST Viewer
MAIN.FRAME.COMPILE_BUTTON.TITLE = Compile
MAIN.FRAME.EVALUATE_BUTTON.TITLE = Evaluate XPath Expression
MAIN.FRAME.COMPILATION.TOOK = Compilation took
MAIN.FRAME.COMPILATION.PROBLEM = Compilation problem:
MAIN.FRAME.EVALUATION.TOOK = Evaluation took
MAIN.FRAME.EVALUATION.PROBLEM = Evaluation problem:
# Source Panel
SOURCE.PANEL.TITLE = Source code
# Tree Panel
AST.PANEL.TITLE = Abstract Syntax Tree
AST.MENU.ATTRIBUTES = Add predicate from {0}'a attributes
AST.MENU.NODE.TITLE = Add {0} to the XPath expression
AST.MENU.NODE.ADD_ABSOLUTE_PATH = Add with absolute path
AST.MENU.NODE.ADD_ALLDESCENDANTS = Add all descentands of this type
# XPath Panel
XPATH.PANEL.TITLE = XPath
XPATH.PANEL.EXPRESSION = Expression
XPATH.PANEL.RESULTS = Results
# Compile Error dialog
COMPILE_ERROR.DIALOG.TITLE = Compilation error
COMPILE_ERROR.PANEL.TITLE = Error message
COMPILE_ERROR.OK_BUTTON.CAPTION = Ok
@@ -0,0 +1,49 @@
package net.sourceforge.pmd.util.viewer.util;
import java.util.ResourceBundle;
/**
* helps with internationalization
*
* @author Boris Gruschko ( boris at gruschko.org )
* @version $Id$
*/
public class NLS {
private final static ResourceBundle bundle;
static {
bundle =
ResourceBundle.getBundle("net.sourceforge.pmd.util.viewer.resources.viewer_strings");
}
/**
* translates the given key to the message
*
* @param key key to be translated
* @return translated string
*/
public static String nls(String key) {
return bundle.getString(key);
}
}
/*
* $Log$
* Revision 1.1 2005/08/15 19:51:42 tomcopeland
* Initial revision
*
* Revision 1.2 2004/09/27 19:42:52 tomcopeland
* A ridiculously large checkin, but it's all just code reformatting. Nothing to see here...
*
* Revision 1.1 2003/09/23 20:32:42 tomcopeland
* Added Boris Gruschko's new AST/XPath viewer
*
* Revision 1.1 2003/09/24 01:33:03 bgr
* moved to a new package
*
* Revision 1.1 2003/09/22 05:21:54 bgr
* initial commit
*
*/
-317
View File
File diff suppressed because it is too large. Load diff
+15 -32
View File
@@ -6,13 +6,13 @@
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
<relativePath />
<relativePath/>
</parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-build</artifactId>
<name>PMD Build Plugin</name>
<version>0.10-SNAPSHOT</version>
<version>0.9-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<description>
<![CDATA[
@@ -73,7 +73,7 @@ only if you modify the java code.
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
@@ -84,12 +84,6 @@ only if you modify the java code.
<localCheckout>true</localCheckout>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
</plugin>
</plugins>
</build>
@@ -98,12 +92,6 @@ only if you modify the java code.
</properties>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
@@ -132,13 +120,6 @@ only if you modify the java code.
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -146,6 +127,13 @@ only if you modify the java code.
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
@@ -156,21 +144,17 @@ only if you modify the java code.
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.4</version>
<version>2.6</version>
<configuration>
<linkXref>true</linkXref>
<sourceEncoding>utf-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>1.6</targetJdk>
<rulesets>
<ruleset>${basedir}/../pmd-core/src/main/resources/rulesets/internal/dogfood.xml</ruleset>
<ruleset>http://pmd.svn.sourceforge.net/svnroot/pmd/trunk/pmd/rulesets/internal/dogfood.xml</ruleset>
</rulesets>
</configuration>
</plugin>
@@ -178,10 +162,9 @@ only if you modify the java code.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.13</version>
<version>2.8</version>
<configuration>
<configLocation>${basedir}/../pmd-core/etc/checkstyle-config.xml</configLocation>
<suppressionsFile>${basedir}/../pmd-core/etc/checkstyle-suppressions.xml</suppressionsFile>
<configLocation>etc/checkstyle-config.xml</configLocation>
</configuration>
</plugin>
</plugins>
@@ -25,183 +25,156 @@ public class PmdBuildTask extends Task {
private URL[] runtimeClasspath;
public URL[] getRuntimeClasspath() {
return runtimeClasspath;
return runtimeClasspath;
}
public void setRuntimeClasspath(URL[] runtimeClasspath) {
this.runtimeClasspath = runtimeClasspath;
this.runtimeClasspath = runtimeClasspath;
}
public String getSiteXml() {
return siteXml;
}
return siteXml;
}
public void setSiteXml(String siteXml) {
this.siteXml = siteXml;
}
public String getSiteXmlTarget() {
return siteXmlTarget;
}
public void setSiteXmlTarget(String siteXmlTarget) {
this.siteXmlTarget = siteXmlTarget;
}
public void setSiteXml(String siteXml) {
this.siteXml = siteXml;
}
public String getSiteXmlTarget() {
return siteXmlTarget;
}
public void setSiteXmlTarget(String siteXmlTarget) {
this.siteXmlTarget = siteXmlTarget;
}
private String rulesetToDocs;
private String rulesetToDocs;
private String mergeRuleset;
private String rulesIndex;
private String indexFilename;
private String mergedRulesetFilename;
/**
/**
* @return the rulesDirectory
*/
public String getRulesDirectory() {
return rulesDirectory;
}
/**
* @param rulesDirectory
* the rulesDirectory to set
* @param rulesDirectory the rulesDirectory to set
*/
public void setRulesDirectory(String rulesDirectory) {
this.rulesDirectory = rulesDirectory;
}
/**
* @return the targetDirectory
*/
public String getTarget() {
return target;
}
/**
* @param targetDirectory
* the targetDirectory to set
* @param targetDirectory the targetDirectory to set
*/
public void setTarget(String targetDirectory) {
this.target = targetDirectory;
}
public void execute() throws BuildException {
PmdBuildTools tool = validate(new RuleSetToDocs());
tool.setTargetDirectory(this.target);
tool.setSiteXml(siteXml);
tool.setSiteXmlTarget(this.siteXmlTarget);
tool.setRulesDirectory(this.rulesDirectory);
tool.setRuntimeClasspath(runtimeClasspath);
try {
tool.convertRulesets();
tool.preSiteGeneration();
} catch (PmdBuildException e) {
throw new BuildException(e);
}
PmdBuildTools tool = validate(new RuleSetToDocs());
tool.setTargetDirectory(this.target);
tool.setSiteXml(siteXml);
tool.setSiteXmlTarget(this.siteXmlTarget);
tool.setRulesDirectory(this.rulesDirectory);
tool.setRuntimeClasspath(runtimeClasspath);
try {
tool.convertRulesets();
tool.preSiteGeneration();
}
catch ( PmdBuildException e) {
throw new BuildException(e);
}
}
private PmdBuildTools validate(RuleSetToDocs tool) throws BuildException {
// Mandatory attributes
if (this.target == null || "".equals(target)) {
throw new BuildException("Attribute targetDirectory is not optional");
}
if (this.rulesDirectory == null || "".equals(this.rulesDirectory)) {
throw new BuildException("Attribute rulesDirectory is not optional");
}
if (this.siteXml == null || "".equals(siteXml)) {
throw new BuildException("Attribute siteXml is not optional");
}
if (this.runtimeClasspath == null || "".equals(runtimeClasspath)) {
throw new BuildException("Attribute pmdClasspath is not optional");
}
// Optional Attributes
if (this.mergedRulesetFilename != null && !"".equals(this.mergedRulesetFilename)) {
tool.setMergedRuleSetFilename(this.mergedRulesetFilename);
}
if (this.rulesIndex != null && !"".equals(this.rulesIndex)) {
tool.getXmlFileTemplater().setGenerateIndexXsl(this.rulesIndex);
}
if (this.rulesetToDocs != null && !"".equals(this.rulesetToDocs)) {
tool.getXmlFileTemplater().setRulesetToDocsXsl(this.rulesetToDocs);
}
if (this.mergeRuleset != null && !"".equals(this.mergeRuleset)) {
tool.getXmlFileTemplater().setMergeRulesetXsl(this.mergeRuleset);
}
return tool;
// Mandatory attributes
if ( this.target == null || "".equals(target) )
throw new BuildException("Attribute targetDirectory is not optional");
if ( this.rulesDirectory == null || "".equals(this.rulesDirectory) )
throw new BuildException("Attribute rulesDirectory is not optional");
if ( this.siteXml == null ||"".equals(siteXml))
throw new BuildException("Attribute siteXml is not optional");
if ( this.runtimeClasspath == null || "".equals(runtimeClasspath)) {
throw new BuildException("Attribute pmdClasspath is not optional");
}
// Optional Attributes
if ( this.mergedRulesetFilename != null && ! "".equals(this.mergedRulesetFilename) )
tool.setMergedRuleSetFilename(this.mergedRulesetFilename);
if ( this.rulesIndex != null && ! "".equals(this.rulesIndex) )
tool.getXmlFileTemplater().setGenerateIndexXsl(this.rulesIndex);
if ( this.rulesetToDocs != null && ! "".equals(this.rulesetToDocs) )
tool.getXmlFileTemplater().setRulesetToDocsXsl(this.rulesetToDocs);
if ( this.mergeRuleset != null && ! "".equals(this.mergeRuleset) )
tool.getXmlFileTemplater().setMergeRulesetXsl(this.mergeRuleset);
return tool;
}
/**
* @return the rulesetToDocs
*/
public String getRulesetToDocs() {
return rulesetToDocs;
}
/**
* @param rulesetToDocs the rulesetToDocs to set
*/
public void setRulesetToDocs(String rulesetToDocs) {
this.rulesetToDocs = rulesetToDocs;
}
/**
* @return the mergeRuleset
*/
public String getMergeRuleset() {
return mergeRuleset;
}
/**
* @param mergeRuleset the mergeRuleset to set
*/
public void setMergeRuleset(String mergeRuleset) {
this.mergeRuleset = mergeRuleset;
}
/**
* @return the rulesIndex
*/
public String getRulesIndex() {
return rulesIndex;
}
/**
* @param rulesIndex the rulesIndex to set
*/
public void setRulesIndex(String rulesIndex) {
this.rulesIndex = rulesIndex;
}
/**
* @return the rulesetToDocs
*/
public String getRulesetToDocs() {
return rulesetToDocs;
}
/**
* @param rulesetToDocs
* the rulesetToDocs to set
*/
public void setRulesetToDocs(String rulesetToDocs) {
this.rulesetToDocs = rulesetToDocs;
}
/**
* @return the mergeRuleset
*/
public String getMergeRuleset() {
return mergeRuleset;
}
/**
* @param mergeRuleset
* the mergeRuleset to set
*/
public void setMergeRuleset(String mergeRuleset) {
this.mergeRuleset = mergeRuleset;
}
/**
* @return the rulesIndex
*/
public String getRulesIndex() {
return rulesIndex;
}
/**
* @param rulesIndex
* the rulesIndex to set
*/
public void setRulesIndex(String rulesIndex) {
this.rulesIndex = rulesIndex;
}
/**
* @return the indexFilename
*/
public String getIndexFilename() {
return indexFilename;
}
/**
* @param indexFilename
* the indexFilename to set
*/
public void setIndexFilename(String indexFilename) {
this.indexFilename = indexFilename;
}
/**
* @return the mergedRulesetFilename
*/
public String getMergedRulesetFilename() {
return mergedRulesetFilename;
}
/**
* @param mergedRulesetFilename
* the mergedRulesetFilename to set
*/
public void setMergedRulesetFilename(String mergedRulesetFilename) {
this.mergedRulesetFilename = mergedRulesetFilename;
}
/**
* @return the indexFilename
*/
public String getIndexFilename() {
return indexFilename;
}
/**
* @param indexFilename the indexFilename to set
*/
public void setIndexFilename(String indexFilename) {
this.indexFilename = indexFilename;
}
/**
* @return the mergedRulesetFilename
*/
public String getMergedRulesetFilename() {
return mergedRulesetFilename;
}
/**
* @param mergedRulesetFilename the mergedRulesetFilename to set
*/
public void setMergedRulesetFilename(String mergedRulesetFilename) {
this.mergedRulesetFilename = mergedRulesetFilename;
}
}
@@ -3,22 +3,23 @@
*/
package net.sourceforge.pmd.build;
/**
* @author Romain PELISSE, belaran@gmail.com
*
*/
public class PmdBuildException extends Exception {
/**
* Default serial ID
*/
private static final long serialVersionUID = 1L;
/**
* Default serial ID
*/
private static final long serialVersionUID = 1L;
public PmdBuildException(String message) {
super(message);
}
public PmdBuildException(String message){
super(message);
}
public PmdBuildException(Throwable e) {
super(e);
}
public PmdBuildException(Throwable e) {
super(e);
}
}
Loaded 30 of 3674 files, more files were not shown because too many files have changed in this diff. Show more