JAVA编程规范_2.如何检测代码的空间范围

如何检测代码的空间范围

代码的空间范围需要限制。例如:行数、列数等等。使用jrscript脚本可以简单的对代码的空间范围进行检测和标注。

脚本实现如下 (语法规范参考jrscript.cn:

#include "java.h"
#include "sys.h"
#include "style.h"
var JCMAXLIN = 200;
string checkJCLineNumber() hooks tk : @"JC" {
	
	if(tk == null) return null;
	
	string warning = null;
	symbol [] symList=tk.values;
	
	if(symList.length>0){
		symbol lastSym=symList[symList.length-1];
	
		if(JCMAXLIN<lastSym.line){
			warning = "The lines of the code file is more than the scope.";
		}
	}
	
	if(warning != null) {
	
		string content = "// The lines of the code file is more than the scope by jrscript.cn";
		log(content);
		symbol [] symList = toSymbolList(content);
		char [] styp = {'L'};
	
		token ctk = createUnitToken(COMMONS, symList, styp);
		insertToken(tk, ctk, 1, false);	
	}
	return warning;
}

#include "java.h”表示hooks函数支持的编程语言。
hooks 方法定义 string checkJCLineNumber() hooks tk : @“JC” 表示该脚本将对检测的所有代码文件进行检测。根据检测结果,如果不符合规范的情况下 return “The lines of the code file is more than the scope.”。hooks函数返回非空时将对检测的文件根据结果进行标注。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值