代码审查工具

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

 

Jupiter

下载:

http://csdl.ics.hawaii.edu/Plone/research/jupiter/

edu.hawaii.ics.csdl.jupiter_3.4.2.jar拷贝到EclipsePlugin目录即可

 

 

 

-----------------------------------------------------------------------

 

Python

Pylinthttp://www.logilab.org/857

      Pydevhttp://pydev.org/)有集成Pylint

      

下载pylint

http://www.logilab.org/project/pylint

 

Pylint Windows 上的安装

1. 安装 Python 的包(高于版本 2.2),右键单击桌面上的我的电脑图标,选择属性,高级,环境变量,在 $PATH 中添加 Python 的安装路径,如 C:/Python26/

2. 使用解压缩工具解压缩所有的包。

3. 打开命令行窗口,使用 cd依次进入 logilab-astnglogilab-common Pylint 解开的文件夹中,运行命令 python setup.py install来安装。

4. 安装完成后,在 Python 的安装路径下出现一个 Scripts 文件夹,里面包含一些 bat 脚本,如 pylint.bat 等。

5. 为了使调用 pylint.bat 的时候不需要输入完整路径,在 Python 的安装目录下创建 pylint.bat 的重定向文件,这是一个纯文本文件 pylint.bat,里面包含 pylint.bat 的实际路径,如:C:/Python26/Scripts/pylint.bat

6. 安装完成后,可以通过 pylint [options] module_or_package来调用 Pylint 了。

 

参考:

http://www.ibm.com/developerworks/cn/linux/l-cn-pylint/index.html

 

 

安装PyDev

After downloading the zip file:

Eclipse 3.4 and 3.5

Extract the contents of the zip file in the eclipse/dropins folder and restart Eclipse.

 

Before Eclipse 3.4

Extract the contents of the zip file on top of Eclipse, making sure the plugins folder is extracted on top of the eclipse/plugins folder and the features is on top of the eclipse/features folder. After that, restart Eclipse with the '-clean' flag, so that Eclipse finds out about it.

 

You can verify if it is correctly installed going to the menu 'window > preferences' and checking if there is a Pydev item under that.

 

Eclipse中设置PydevInterpreter路径

 

Eclipse中配置使用pylint

(1)Window -> preferences -> Pydev -> Pylint

    选中"Use pylint?"

    在输入lint.py的地址,例如"E:/pylint-0.22.0/lint.py"

(2)Project->Properties->PyDev-PYTHONPATH

     增添项目的源文件目录到"Project Source Folders"

(3)选中Project->Build Automatically,这样保存修改时pylint就会自动check项目中的代码,否则就要用Ctrl+B手动build并触发pylint

PS:command模式使用lint.py

lint.py --files-output=y --reports=y src/   (需要先把lint.py所在目录添加到PATH)

会生成两个pylint_开头的文件

 

 

 

--------------------------------------------------------------------------

 

Perl

Perl-Critichttp://search.cpan.org/dist/Perl-Critic/

 

下载并安装Perl

http://www.activestate.com/activeperl/downloads

 

 

安装EclipsePerl插件EPIC

http://www.epic-ide.org/

安装方法参考:

http://www.epic-ide.org/download.php

http://www.epic-ide.org/faq.php#requirements

 

 

下载并安装Perl-Critic所依赖的包进行安装,安装方法:

 perl Makefile.PL

 nmake

 nmake test

 nmake install

 

下载并安装Perl-Critichttp://search.cpan.org/dist/Perl-Critic/):

 cd E:/Perl-Critic-1.109

 perl Build.pl

 Build

 build test

 build install

参考:

http://cpansearch.perl.org/src/ELLIOTJS/Perl-Critic-1.109/INSTALL

 

Eclipse中设置Perl-Critic

 

 

 

 

-------------------------------------------------------------------------

 

Java

CheckStyle

1、安装CheckStyle

下载:

http://sourceforge.net/projects/checkstyle/files/

 

2、使用方法

checkstyle-5.3-all.jar添加到CLASS_PATH

 

命令行使用:

E:/checkstyle-5.3>java -jar checkstyle-5.3-all.jar -c sun_checks.xml E:/EclipseWorkspace/JavaProject1/src/TestCheckStyle.java

参考:

E:/checkstyle-5.3/site/cmdline.html

 

 

配置:

Module

Properties

参考:

E:/checkstyle-5.3/site/config.html

 

 

自定义Checkstyle:

E:/checkstyle-5.3/site/writingchecks.html

 

 

 

Eclipse插件:

下载:

http://eclipse-cs.sourceforge.net/downloads.html

安装:

The plugin can be installed from the archived update site in the following ways:

1via Eclipse's P2 Installation Manager similar as described above, pointing to the archive file instead

2extracted into Eclipse's dropins folder. Anyway this is not particularly recommended, so if you don't know what I am talking about, don't bother.

配置使用参考:

http://eclipse-cs.sourceforge.net/basic_creating_config.html

 

 

 

 

FindBugs

1、安装FindBugs

下载

http://findbugs.sourceforge.net/downloads.html

解压缩即可

 

FindBugs帮助文档:

E:/findbugs-1.3.6/doc/manual/index.html

 

2、使用方法

java -jar $FINDBUGS_HOME/lib/findbugs.jar

或者直接执行$FINDBUGS_HOME/bin/findbugs.bat

 

3FindBugsEclipse插件使用方法

下载安装FindBugsEclipse插件:

You can also manually download the plugin from the following link: http://prdownloads.sourceforge.net/findbugs/edu.umd.cs.findbugs.plugin.eclipse_1.3.6.20081113.zip?download.

Extract it in Eclipse's "plugins" subdirectory. (So <eclipse_install_dir>/plugins/edu.umd.cs.findbugs.plugin.eclipse_1.3.6.20081113/findbugs.png should be the path to the FindBugs logo.)

 

Once the plugin is extracted, start Eclipse and choose Help About Eclipse Platform Plug-in Details. You should find a plugin called "FindBugs Plug-in" provided by "FindBugs Project".

 

配置Java项目自动运行FindBugs检查:

You may customize how FindBugs runs by opening the Properties dialog for a Java project, and choosing the "Findbugs" property page. Options you may choose include:

Enable or disable the "Run FindBugs Automatically" checkbox. When enabled, FindBugs will run every time you modify a Java class within the project.

Choose minimum warning priority and enabled bug categories. These options will choose which warnings are shown. For example, if you select the "Medium" warning priority, only Medium and High priority warnings will be shown. Similarly, if you uncheck the "Style" checkbox, no warnings in the Style category will be displayed.

Select detectors. The table allows you to select which detectors you want to enable for your project.

 

配置Filter

Priority

1 to match high-priority warnings, 2 to match medium-priority warnings, or 3 to match low-priority warnings.

例如:

<FindBugsFilter>

     <Match>

       <Priority value="2" />

       <Bug code="EI2,EI" />

     </Match>        

</FindBugsFilter>

参考:

file:///E:/findbugs-1.3.6/doc/manual/filter.html#d0e1744

 

 

在代码中用Annotations抑制FindBugs的警告信息:

FindBugs supports several annotations to express the developer's intent so that FindBugs can issue warnings more appropriately. You need to use Java 5 to use annotations, and must place the annotations.jar and jsr305.jar files in the classpath while compiling your program.

例如:

       @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="EI",justification="this is not a bug!")

       public String[] getName() {

              //String[] temp = name;

              //return temp;

              return name;

       }

 

 

 

PMD

 

1、安装

下载pmd-bin-x.xx.ziphttp://sourceforge.net/projects/pmd/files/

解压缩即可

 

PMDEclipse插件安装

pmd.eclipse.plugin_3.2.5安装到eclipse-sdk-3.4.2

net.sourceforge.pmd.eclipse.plugin_3.2.5目录中的net.sourceforge.pmd.eclipse_3.2.5.v200810131150文件夹拷贝到Eclipsefeature目录中

net.sourceforge.pmd.eclipse.plugin_3.2.5.v200810131150.jar拷贝到Eclipseplugin目录中

 

PMD帮助文档:

E:/pmd-bin-4.2.4/pmd-4.2.4/docs

 

2PMD使用方法

 

命令行使用方法

Type pmd [filename|jar or zip file containing source code|directory] [report format] [ruleset file], i.e:

 

C:/tmp/pmd-4.2.4/pmd/bin>pmd c:/data/pmd/pmd/test-data/Unused1.java xml rulesets/unusedcode.xml

 

<?xml version="1.0"?><pmd>

<file name="c:/data/pmd/pmd/test-data/Unused1.java">

<violation line="5" rule="UnusedLocalVariable">

Avoid unused local variables such as 'fr'

</violation>

</file></pmd>

 

You can pass a file name, a directory name, or a jar or zip file name containing Java source code to PMD.

 

Also, the PMD binary distribution includes the ruleset files inside the jar file - even though the "rulesets/unusedcode.xml" parameter above looks like a filesystem reference, it's really being used by a getResourceAsStream() call to load it out of the PMD jar file. And the same applies to the example below.

 

If you are want to run PMD without the batch file, you can do a:

C:/data/pmd/pmd>java -cp lib/pmd-4.2.4.jar;lib/jaxen-1.1.1.jar;lib/asm-3.1.jar

                     net.sourceforge.pmd.PMD

                     c:/j2sdk1.4.1_01/src/java/lang xml

                     rulesets/imports.xml

 

PMD规则集:

E:/pmd-bin-4.2.4/pmd-4.2.4/docs/rules

 

抑制PMD警告的方法

Annotations

NOPMD

 

CPD找出冗余代码

aCPD命令行使用方式:

E:/pmd-bin-4.2.4/pmd-4.2.4/lib>java -cp pmd-4.2.4.jar net.sourceforge.pmd.cpd.CPD --minimum-tokens 5 --files E:/EclipseWorkspace/JavaProject1/src

Found a 8 line (23 tokens) duplication in the following files:

Starting at line 12 of E:/EclipseWorkspace/JavaProject1/src/TestPMD.java

Starting at line 21 of E:/EclipseWorkspace/JavaProject1/src/TestPMD.java

 

        public int add_duplicate()

        {

                int a=0;

                int b=0;

                int c=0;

                c=a+b;

                return c;

        }

b、使用cpdgui.batpmd-bin-4.2.4/pmd-4.2.4/bin/cpdgui.bat

 

 

3、规则自定义

参考:E:/pmd-bin-4.2.4/pmd-4.2.4/docs/howtowritearule.html

 

4PMD最佳实践

E:/pmd-bin-4.2.4/pmd-4.2.4/docs/bestpractices.html

 

 

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/gdhjgfr/article/details/84081660