当前位置: 首页>>代码示例>>Java>>正文


Java ObligationPolicyDatabaseActionType类代码示例

本文整理汇总了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);
        }
    }
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:27,代码来源:BuildObligationPolicyDatabase.java

示例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));
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:14,代码来源:BuildObligationPolicyDatabase.java

示例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));
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:60,代码来源:BuildObligationPolicyDatabase.java

示例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));
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:48,代码来源:BuildObligationPolicyDatabase.java

示例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));
    }
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:61,代码来源:BuildObligationPolicyDatabase.java


注:本文中的edu.umd.cs.findbugs.ba.obl.ObligationPolicyDatabaseActionType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。