本文整理汇总了Java中edu.umd.cs.findbugs.ba.obl.ObligationPolicyDatabaseActionType类的典型用法代码示例。如果您正苦于以下问题:Java ObligationPolicyDatabaseActionType类的具体用法?Java ObligationPolicyDatabaseActionType怎么用?Java ObligationPolicyDatabaseActionType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObligationPolicyDatabaseActionType类属于edu.umd.cs.findbugs.ba.obl包,在下文中一共展示了ObligationPolicyDatabaseActionType类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitClass
import edu.umd.cs.findbugs.ba.obl.ObligationPolicyDatabaseActionType; //导入依赖的package包/类
public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisException {
XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, classDescriptor);
// Is this class an obligation type?
Obligation thisClassObligation = database.getFactory().getObligationByType(xclass.getClassDescriptor());
// Scan methods for uses of obligation-related annotations
for (XMethod xmethod : xclass.getXMethods()) {
// Is this method marked with @CreatesObligation?
if (thisClassObligation != null) {
if (xmethod.getAnnotation(createsObligation) != null) {
database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.ADD,
ObligationPolicyDatabaseEntryType.STRONG, thisClassObligation));
}
// Is this method marked with @DischargesObligation?
if (xmethod.getAnnotation(dischargesObligation) != null) {
database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, thisClassObligation));
}
}
addObligations(xmethod);
}
}
示例2: addFileStreamEntries
import edu.umd.cs.findbugs.ba.obl.ObligationPolicyDatabaseActionType; //导入依赖的package包/类
/**
* General method for adding entries for File
* InputStream/OutputStream/Reader/Writer classes.
*/
private void addFileStreamEntries(String kind) {
Obligation obligation = database.getFactory().addObligation("java.io." + kind);
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.io.File" + kind)),
new ExactStringMatcher("<init>"), new RegexStringMatcher(".*"), false, ObligationPolicyDatabaseActionType.ADD,
ObligationPolicyDatabaseEntryType.STRONG, obligation));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.io." + kind)),
new ExactStringMatcher("close"), new ExactStringMatcher("()V"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, obligation));
}
示例3: addBuiltInPolicies
import edu.umd.cs.findbugs.ba.obl.ObligationPolicyDatabaseActionType; //导入依赖的package包/类
private void addBuiltInPolicies() {
// Add the database entries describing methods that add and delete
// file stream/reader obligations.
addFileStreamEntries("InputStream");
addFileStreamEntries("OutputStream");
addFileStreamEntries("Reader");
addFileStreamEntries("Writer");
Obligation javaIoInputStreamObligation = database.getFactory().getObligationByName("java.io.InputStream");
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.lang.Class")),
new ExactStringMatcher("getResourceAsStream"),
new ExactStringMatcher("(Ljava/lang/String;)Ljava/io/InputStream;"), false,
ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, javaIoInputStreamObligation));
Obligation javaIoOutputStreamObligation = database.getFactory().getObligationByName("java.io.OutputStream");
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil
.getObjectTypeInstance("java.util.logging.StreamHandler")), new ExactStringMatcher("setOutputStream"),
new ExactStringMatcher("(Ljava/io/OutputStream;)V"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, javaIoOutputStreamObligation));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil
.getObjectTypeInstance("java.io.FileOutputStream")), new ExactStringMatcher("getChannel"),
new ExactStringMatcher("()Ljava/nio/channels/FileChannel;"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, javaIoOutputStreamObligation));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil
.getObjectTypeInstance("java.io.FileInputStream")), new ExactStringMatcher("getChannel"),
new ExactStringMatcher("()Ljava/nio/channels/FileChannel;"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, javaIoInputStreamObligation));
// Database obligation types
Obligation connection = database.getFactory().addObligation("java.sql.Connection");
Obligation statement = database.getFactory().addObligation("java.sql.Statement");
Obligation resultSet = database.getFactory().addObligation("java.sql.ResultSet");
// Add factory method entries for database obligation types
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.DriverManager")),
new ExactStringMatcher("getConnection"), new RegexStringMatcher("^.*\\)Ljava/sql/Connection;$"), false,
ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, connection));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.Connection")),
new ExactStringMatcher("createStatement"), new RegexStringMatcher("^.*\\)Ljava/sql/Statement;$"), false,
ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, statement));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.Connection")),
new ExactStringMatcher("prepareStatement"), new RegexStringMatcher("^.*\\)Ljava/sql/PreparedStatement;$"), false,
ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, statement));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.Statement")),
new ExactStringMatcher("executeQuery"), new RegexStringMatcher("^.*\\)Ljava/sql/ResultSet;$"), false,
ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, resultSet));
// Add close method entries for database obligation types
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.Connection")),
new ExactStringMatcher("close"), new ExactStringMatcher("()V"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, connection));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.Statement")),
new ExactStringMatcher("close"), new ExactStringMatcher("()V"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, statement, resultSet));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.ResultSet")),
new ExactStringMatcher("close"), new ExactStringMatcher("()V"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, resultSet));
}
示例4: handleWillCloseWhenClosed
import edu.umd.cs.findbugs.ba.obl.ObligationPolicyDatabaseActionType; //导入依赖的package包/类
/**
* Handle a method with a WillCloseWhenClosed parameter annotation.
*/
private void handleWillCloseWhenClosed(XMethod xmethod, Obligation deletedObligation) {
if (deletedObligation == null) {
if (DEBUG_ANNOTATIONS) {
System.out.println("Method " + xmethod.toString() + " is marked @WillCloseWhenClosed, "
+ "but its parameter is not an obligation");
}
return;
}
// See what type of obligation is being created.
Obligation createdObligation = null;
if (xmethod.getName().equals("<init>")) {
// Constructor - obligation type is the type of object being created
// (or some supertype)
createdObligation = database.getFactory().getObligationByType(xmethod.getClassDescriptor());
} else {
// Factory method - obligation type is the return type
Type returnType = Type.getReturnType(xmethod.getSignature());
if (returnType instanceof ObjectType) {
try {
createdObligation = database.getFactory().getObligationByType((ObjectType) returnType);
} catch (ClassNotFoundException e) {
reporter.reportMissingClass(e);
return;
}
}
}
if (createdObligation == null) {
if (DEBUG_ANNOTATIONS) {
System.out.println("Method " + xmethod.toString() + " is marked @WillCloseWhenClosed, "
+ "but its return type is not an obligation");
}
return;
}
// Add database entries:
// - parameter obligation is deleted
// - return value obligation is added
database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, deletedObligation));
database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.ADD,
ObligationPolicyDatabaseEntryType.STRONG, createdObligation));
}
示例5: addBuiltInPolicies
import edu.umd.cs.findbugs.ba.obl.ObligationPolicyDatabaseActionType; //导入依赖的package包/类
private void addBuiltInPolicies() {
// Add the database entries describing methods that add and delete
// file stream/reader obligations.
addFileStreamEntries("InputStream");
addFileStreamEntries("OutputStream");
addFileStreamEntries("Reader");
addFileStreamEntries("Writer");
Obligation javaIoInputStreamObligation = database.getFactory().getObligationByName("java.io.InputStream");
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.lang.Class")),
new ExactStringMatcher("getResourceAsStream"),
new ExactStringMatcher("(Ljava/lang/String;)Ljava/io/InputStream;"), false,
ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, javaIoInputStreamObligation));
Obligation javaIoOutputStreamObligation = database.getFactory().getObligationByName("java.io.OutputStream");
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil
.getObjectTypeInstance("java.util.logging.StreamHandler")), new ExactStringMatcher("setOutputStream"),
new ExactStringMatcher("(Ljava/io/OutputStream;)V"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, javaIoOutputStreamObligation));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil
.getObjectTypeInstance("java.io.FileOutputStream")), new ExactStringMatcher("getChannel"),
new ExactStringMatcher("()Ljava/nio/channels/FileChannel;"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, javaIoOutputStreamObligation));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil
.getObjectTypeInstance("java.io.FileInputStream")), new ExactStringMatcher("getChannel"),
new ExactStringMatcher("()Ljava/nio/channels/FileChannel;"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, javaIoInputStreamObligation));
// Database obligation types
Obligation connection = database.getFactory().addObligation("java.sql.Connection");
Obligation statement = database.getFactory().addObligation("java.sql.Statement");
Obligation resultSet = database.getFactory().addObligation("java.sql.ResultSet");
// Add factory method entries for database obligation types
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.DriverManager")),
new ExactStringMatcher("getConnection"), new RegexStringMatcher("^.*\\)Ljava/sql/Connection;$"), false,
ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, connection));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.Connection")),
new ExactStringMatcher("createStatement"), new RegexStringMatcher("^.*\\)Ljava/sql/Statement;$"), false,
ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, statement));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.Connection")),
new ExactStringMatcher("prepareStatement"), new RegexStringMatcher("^.*\\)Ljava/sql/PreparedStatement;$"), false,
ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, statement));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.Statement")),
new ExactStringMatcher("executeQuery"), new RegexStringMatcher("^.*\\)Ljava/sql/ResultSet;$"), false,
ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, resultSet));
// Add close method entries for database obligation types
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.Connection")),
new ExactStringMatcher("close"), new ExactStringMatcher("()V"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, connection));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.Statement")),
new ExactStringMatcher("close"), new ExactStringMatcher("()V"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, statement, resultSet));
database.addEntry(new MatchMethodEntry(new SubtypeTypeMatcher(BCELUtil.getObjectTypeInstance("java.sql.ResultSet")),
new ExactStringMatcher("close"), new ExactStringMatcher("()V"), false, ObligationPolicyDatabaseActionType.DEL,
ObligationPolicyDatabaseEntryType.STRONG, resultSet));
}