|
查看: 1245|回复: 3
|
Java 的问题
[复制链接]
|
|
|
本帖最后由 书璇 于 31-1-2010 08:58 PM 编辑
有个关于我的功课的问题,我需要做一个可以自动算出 source line of code , comment line 和cyclomatic complexity的程式。
Example: user input the java 的coding into a JtextArea, 过后按start button, 就会自动算出那个coding的source line of code , comment line 和cyclomatic complexity。 result 会出现在另外一个的JtextArea.
我打算用Pattern and matcher.
//calculate the statement line
int SLOC = 0;
String input = textArea.getText();
Pattern p1 = Pattern.compile("(; )" );
Matcher m1 = p1.Matcher(input);
boolean f = m1.find();
if(f == true){
SLOC++;
}
//calculate the Comment line
int CLOC = 0;
Pattern p2 = Pattern.compile("(\\/\\/)" );
Matcher m2 = p2.Matcher(input);
boolean f1 = m2.find();
if(f1 == true){
CLOC++;
}
//Total line = CLOC +SLOC;
//calculate the Cyclomatic Complexity
int count= 0;
Pattern p3 = Pattern.compile("if|else| for|.....等等" );
Matcher m3 = p3.Matcher(input);
boolean f2 = m3.find();
if(f2 == true){
count++;
}
int cc = count +1 ;
请问下我要怎样把 算到出来的数据出现在另外一个的JtextArea?? |
|
|
|
|
|
|
|
|
|
|
发表于 31-1-2010 10:08 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 1-2-2010 01:31 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 2-2-2010 07:53 PM
|
显示全部楼层
你的问题还蛮奇怪的,会用regex不会用textarea我还是第一次见。
java的所有control都可以通过调用method来改变属性,去下载他们的java doc让后与你的ide整合吧。
最快就是google java [control name]第一个结果都是Java doc来的,读一读method list就是了。 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|