工具下载地址:http://www.harukizaemon.com/simian/get_it_now.html
1. simian命令行的格式:
java -jar simian.jar [options] [files]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=FNAME | Reads the configuration from the specifiedfile |
| -defaultLanguage=LANG | Assumes files are in the specified language if none can be inferred |
| -excludes=SPEC | Excludes 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:END | Ignores 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=SPEC | Including files matching the specified pattern |
| -language=LANG | Assumes ALL files are in the specified language |
| -reportDuplicateText[+/-] | Prints the duplicate text in reports |
| -threshold=COUNT | Matches will contain at least the specified number of lines |
3. 参照下图分5个步骤:
- 打开cmd,cd进入simian-2.3.35文件夹的bin目录;
- 执行命令
java -jar simian-2.35.jar; - 后面可以根据自己的需求添加选择;(如
-ignoreVariableNames+表示忽略变量名,+号表示要添加这个属性,-号表示不添加这个属性(也可以不写);-threshold=10表示10行以上的重复才统计;) - 需要扫描的文件的路径
E:\...\main\**.java;(**.java表示main文件夹下的所有java文件;) - 将统计出来的数据写入生成的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性能评测优化》















