佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

搜索
查看: 1245|回复: 3

Java 的问题

[复制链接]
发表于 31-1-2010 08:56 PM | 显示全部楼层 |阅读模式
本帖最后由 书璇 于 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??
回复

使用道具 举报


ADVERTISEMENT

发表于 31-1-2010 10:08 PM | 显示全部楼层
http://java.sun.com/j2se/1.5.0/d ... wing/JTextArea.html
去查查 javax.swing.JTextArea 里, 有什么API method可以用就可以啦..

还是老得一句, 去学一学用google吧..
如果你有打算成为programmer..
回复

使用道具 举报

发表于 1-2-2010 01:31 AM | 显示全部楼层
赞成jasonmun说的
回复

使用道具 举报

发表于 2-2-2010 07:53 PM | 显示全部楼层
你的问题还蛮奇怪的,会用regex不会用textarea我还是第一次见。
java的所有control都可以通过调用method来改变属性,去下载他们的java doc让后与你的ide整合吧。
最快就是google java [control name]第一个结果都是Java doc来的,读一读method list就是了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2026 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 15-5-2026 02:56 AM , Processed in 0.053884 second(s), 12 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表