使用Simian工具扫描重复代码


工具下载地址:http://www.harukizaemon.com/simian/get_it_now.html

1. simian命令行的格式:

  1. java -jar simian.jar [options] [files]
  2. simian.exe [options] [files]

2. Usage: [options] [files]

命令描述
-balanceCurlyBraces[+/-]Accounts for curly braces when breaking lines
-balanceParentheses[+/-]Accounts for parentheses when breaking lines
-balanceSquareBrackets[+/-]Accounts for square brackets when breaking lines
-config=FNAMEReads the configuration from the specifiedfile
-defaultLanguage=LANGAssumes files are in the specified language if none can be inferred
-excludes=SPECExcludes files matching the specified pattern
-failOnDuplication[+/-/%]Exits with a failure return code if duplication detected
-formatter=TYPE[:FNAME]Uses the specified output format when reporting
-ignoreBlocks=START:ENDIgnores all lines between START/END
-ignoreCharacterCase[+/-]Matches character literals irrespective of case
-ignoreCharacters[+/-]Completely ignores character literals
-ignoreCurlyBraces[+/-]Completely ignores curly braces
-ignoreIdentifierCase[+/-]Matches identifiers irresepctive of case
-ignoreIdentifiers[+/-]Completely ignores identifiers
-ignoreLiterals[+/-]Completely ignores all literals (strings, numbers and characters)
-ignoreModifiers[+/-]Ignores modifiers (public, private, static, etc.)
-ignoreNumbers[+/-]Completely ignores numbers
-ignoreOverlappingBlocks[+/-]Ignores blocks that wholly or partially overlap
-ignoreRegions[+/-]Ignores all lines between #region/#endregion
-ignoreStringCase[+/-]Matches string literals irrespective of case
-ignoreStrings[+/-]Completely ignores the contents of strings
-ignoreSubtypeNames[+/-]Matches on similar type names (eg. Reader and FilterReader)
-ignoreVariableNames[+/-]Completely ignores variable names (fields, parameters and locals)
-includes=SPECIncluding files matching the specified pattern
-language=LANGAssumes ALL files are in the specified language
-reportDuplicateText[+/-]Prints the duplicate text in reports
-threshold=COUNTMatches will contain at least the specified number of lines

3. 参照下图分5个步骤:

这里写图片描述

  1. 打开cmd,cd进入simian-2.3.35文件夹的bin目录;
  2. 执行命令java -jar simian-2.35.jar
  3. 后面可以根据自己的需求添加选择;(如-ignoreVariableNames+ 表示忽略变量名,+号表示要添加这个属性,-号表示不添加这个属性(也可以不写);-threshold=10 表示10行以上的重复才统计;)
  4. 需要扫描的文件的路径E:\...\main\**.java;(**.java表示main文件夹下的所有java文件;)
  5. 将统计出来的数据写入生成的duplicates10.txt文件中;(文件名随意,默认生成在simian的bin目录下;)

4. 生成的duplicates10.txt内容:

Similarity Analyser 2.3.35 - http://www.harukizaemon.com/simian
Copyright (c) 2003-2013 Simon Harris. All rights reserved.
Simian is not free unless used solely for non-commercial or evaluation purposes.
// 配置的options选项,如ignoreVariableNames=true, threshold=10等
{failOnDuplication=true, ignoreCharacterCase=true, ignoreCurlyBraces=true, ignoreIdentifierCase=true, ignoreModifiers=true, ignoreStringCase=true, ignoreVariableNames=true, threshold=7}
Found 12 duplicate lines in the following files:
Between lines 64 and 75 in E:…\main\java\com\example\ui\activity\MainActivity.java
Between lines 62 and 73 in E:…\main\java\com\example\ui\activity\MainActivity.java
Found 13 duplicate lines in the following files:
Between lines 81 and 98 in E:…\main\java\com\example\module_widget\widget\Bezier3.java
Between lines 68 and 84 in E:…\main\java\com\example\module_widget\widget\Bezier2.java

……

Found 173 duplicate lines in 19 blocks in 9 files
Processed a total of 1409 significant (2905 raw) lines in 25 files
Processing time: 0.047sec



参考:

《移动App性能评测优化》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值