java - 在 Java 包上使用“ls”命令时出现不支持的方案错误
问题描述
我正在开发一个函数,它为 Java M3 提供每个包的代码量列表。这个函数看起来像这样:
public list[int] calculateSizePerComponent(M3 model){
set[loc] packages = packages(model);
list[int] componentSizes = [];
for(package <- packages){
list[loc] classFiles = [x | x <- package.ls, endsWith(x.file, ".java")];
if(size(classFiles)>0){
int sourceSize = 0;
for(classFile <- classFiles){
sourceSize+=getLinesOfCode(classFile).linesOfCode;
}
componentSizes += sourceSize;
}
}
return componentSizes;
}
我使用以下函数来计算 Java 编译单元(适用于其他示例)中的代码行数(体积):
public tuple[int linesOfCode,int blankLines,int commentLines] getLinesOfCode(loc location) {
int linesOfCode = 0;
int blankLines = 0;
int commentLines = 0;
bool incomment = false;
srcLines = readFileLines(location);
for (line <- srcLines) {
switch(line){
case /^\s*\/\/\s*\w*/: commentLines += 1; // Line preceded by '//'
case /((\s*\/\*[\w\s]+\*\/)+[\s\w]+(\/\/[\s\w]+$)*)+/: linesOfCode += 1; // Line containing Java code containing any amount of comments. Example: code /**comment*/ code /**comment*/ code
case /^\s*\/\*?[\w\s\?\@]*\*\/$/: commentLines += 1; // Line containing single line comment: /*comment*/
case /\s*\/\*[\w\s]*\*\/[\s\w]+/: linesOfCode += 1; // Line containing a comment, but also code. Example: /**comment*/ code
case /^[\s\w]*\*\/\s*\w+[\s\w]*/: {incomment = false; linesOfCode += 1;} // Line closing a multi-line comment, but also containing code. Example: comment*/ code
case /^\s*\/\*\*?[^\*\/]*$/: {incomment = true; commentLines += 1;} // Line opening a multi-line comment, Example: /**comment
case /\s*\*\/\s*$/: {commentLines += 1; incomment = false;} // Line closing a multi-line comment, Example: comment*/
case /^\s*$/: blankLines += 1; // Blank line
default: if (incomment) commentLines += 1; else linesOfCode += 1;
}
}
return <linesOfCode,blankLines,commentLines>;
}
但是,package.ls
似乎返回具有错误方案的结果。因此,我在readFileLines
通话中收到以下错误:
|std:///IO.rsc|(14565,775,<583,0>,<603,43>): IO("Unsupported scheme java+package")
at *** somewhere ***(|std:///IO.rsc|(14565,775,<583,0>,<603,43>))
at readFileLines(|project://Software_Evolution/src/metrics/volume.rsc|(1911,8,<49,26>,<49,34>))
at calculateSizePerComponent(|project://Software_Evolution/src/metrics/componentsize.rsc|(1996,38,<64,16>,<64,54>))
at getComponentSize(|project://Software_Evolution/src/metrics/componentsize.rsc|(267,1112,<15,0>,<42,1>))
at $root$(|prompt:///|(0,30,<1,0>,<1,30>))
当我打印位置时,我得到以下信息:
|java+package:///smallsql/database/language/Language.java|
这是不正确的,因为这是一个 java 编译单元而不是一个包。如何获取此文件中的代码行?
解决方案
Rascal 函数resolveLocation
最终解决了这个问题。因此package.ls
,我不得不使用resolveLocation(package).ls
.
推荐阅读
- css - 删除元素的问题,无法正常工作
- laravel - 在哪里放置 Laravel Excel 的视图文件?
- reactjs - ReferenceError:找不到变量:React Native 0.60.4 中的状态
- java - android - Google Play 商店上未显示更新按钮
- java - 自动将日期存入数据库
- java - 如何将以下 JAVA 加密重现为等效的 NODEJS(使用 node-rsa 或加密模块)?
- java - 抛出 org.apache.shiro.session.UnknownSessionException: 注销后没有带有 id 的会话并将请求重定向到登录页面
- json - 在复制数据中将数据从源丢失到接收器
- postgresql - 有没有办法在 TypeORM 的选择部分绑定参数?
- android - 如何在textview中的其他文本上显示$符号