我正在尝试添加一个检测器,它将检测System.out.println()的发生.正如在解释这个帖子,我已经写了检测类,findbugs.xml文件和messages.xml文件.我创建了一个包含我的探测器类,findbugs.xml和messages.xml文件的jar.我在我的eclipse环境中添加了这个jar(window-> preferences-> java-> findbugs-> Plugins和misc.Settings).但它显示无效输入.
探测器类:
package findbugs.custom.detector;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
import edu.umd.cs.findbugs.classfile.ClassDescriptor;
import edu.umd.cs.findbugs.classfile.FieldDescriptor;
public class CallToSystemOutPrintlnDetector2 extends OpcodeStackDetector {
private BugReporter bugReporter;
public CallToSystemOutPrintlnDetector2(BugReporter bugReporter) {
super();
this.bugReporter = bugReporter;
}
public void sawOpcode(int seen) {
if (seen == GETSTATIC){
try {
FieldDescriptor operand = getFieldDescriptorOperand();
ClassDescriptor classDescriptor = operand.getClassDescriptor();
if ("java/lang/System".equals(classDescriptor.getClassName()) &&
("err".equals(operand.getName())||"out".equals(operand.getName()))) {
reportBug();
}
} catch (Exception e) {
//ignore
}
}
}
private void reportBug(){
this.bugReporter.reportBug(getBugInstance());
}
private BugInstance …Run Code Online (Sandbox Code Playgroud) 在应用程序开发中,我经常需要使用'Constants'和'Enums'。就我使用的策略而言,我将所有'Constants'保存在一个名为'Constants'的单独类中,但我不确定是否应该保留所有Enums在一个单独的类中,因为我使用“常量”?或者我应该在我需要的那些班级中保留枚举?或者我也应该将 Contants 类中的枚举保留为“静态”。我的问题是保留所有常量和枚举的正确位置是什么。