gpt4 book ai didi

java - 在标准 PMD 圈复杂度插件上获取 ClassNotFoundException

转载 作者:太空宇宙 更新时间:2023-11-04 09:10:01 24 4
gpt4 key购买 nike

我在 Windows 10 上使用 PMD 版本 6.20.0,并且尝试在我认为简单的 Java 代码上使用圈复杂度插件,只是为了看看事情是否有效。我有一个 .java 文件 CCExample.java,其代码如下(提供的目的只是为了让每个人都可以看到我正在使用的源文件,而不是要求对以下代码进行注释,我知道这是低效的,并且仅用于我给出的工程演讲中的示例):

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class CCExample
{
public static String reduceString(String s, int index)
{
int lastIndex = s.length() - 1;

if (s.length() == 0)
{
return "Empty String";
}
else if (index >= lastIndex)
{
if (isReduced(s, 0))
{
return s;
}
else
{
return reduceString(s, 0);
}
}
else if (s.charAt(index) == s.charAt(index + 1))
{
if (index + 1 < lastIndex)
{
return reduceString(s.substring(0, index) + s.substring(index + 2, s.length()), index);
}
else
{
return reduceString(s.substring(0, index), index);
}
}
else
{
return reduceString(s, index + 1);
}
}

public static boolean isReduced(String s, int index)
{
int lastIndex = s.length() - 1;

if (index == lastIndex || s.length() == 0)
{
return true;
}
else if (s.charAt(index) != s.charAt(index + 1))
{
return isReduced(s, index + 1);
}
else
{
return false;
}
}

public static void main(final String[] args)
{
if (args.length != 1)
{
System.out.println("Usage: java CCExample <string>");
}
else
{
final String s = args[0];
System.out.println(reduceString(s, 0));
}
}
}

使用上面的单个 .java 文件,我运行以下 PMD 命令:

pmd -d CCExample.java -debug -R category/java/design.xml/CyclomaticComplexity -f text

在调试日志中我得到以下内容:

Jan 15, 2020 2:35:58 PM net.sourceforge.pmd.RulesetsFactoryUtils printRuleNamesInDebug
FINER: Loaded rule CyclomaticComplexity
Jan 15, 2020 2:35:58 PM net.sourceforge.pmd.processor.PmdRunnable call
FINE: Processing C:\Temp\CCExample.java
Jan 15, 2020 2:35:58 PM net.sourceforge.pmd.lang.java.typeresolution.ClassTypeResolver visit
FINE: Could not find class CCExample, due to: java.lang.ClassNotFoundException: CCExample

我做错了什么,它找不到 CCExample 类?我的一些 .java 文件得到了圈复杂度数字,其他文件得到了上述错误。我是否有一些格式设置不正确?

最佳答案

将此问题发布给 PMD,并被告知这是设计使然。默认情况下,特定插件不会显示 10 以下的复杂性信息,我的代码示例太简单了。 ClassNotFoundException 也可以被忽略。

关于java - 在标准 PMD 圈复杂度插件上获取 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59760664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com