Search in sources :

Example 1 with CompoundMatcher

use of edu.umd.cs.findbugs.filter.CompoundMatcher in project spotbugs by spotbugs.

the class SAXBugCollectionHandler method addMatcher.

private void addMatcher(Matcher m) {
    if (m == null) {
        throw new IllegalArgumentException("matcher must not be null");
    }
    CompoundMatcher peek = matcherStack.peek();
    if (peek == null) {
        throw new NullPointerException("Top of stack is null");
    }
    peek.addChild(m);
    if (nextMatchedIsDisabled) {
        if (peek instanceof Filter) {
            ((Filter) peek).disable(m);
        } else {
            assert false;
        }
        nextMatchedIsDisabled = false;
    }
}
Also used : CompoundMatcher(edu.umd.cs.findbugs.filter.CompoundMatcher) Filter(edu.umd.cs.findbugs.filter.Filter)

Example 2 with CompoundMatcher

use of edu.umd.cs.findbugs.filter.CompoundMatcher in project spotbugs by spotbugs.

the class SAXBugCollectionHandler method parseMatcher.

private void parseMatcher(String qName, Attributes attributes) throws SAXException {
    if (DEBUG) {
        System.out.println(elementStack + " " + qName + " " + matcherStack);
    }
    String disabled = getOptionalAttribute(attributes, "disabled");
    nextMatchedIsDisabled = "true".equals(disabled);
    if ("Bug".equals(qName)) {
        addMatcher(new BugMatcher(getOptionalAttribute(attributes, "code"), getOptionalAttribute(attributes, "pattern"), getOptionalAttribute(attributes, "category")));
    } else if ("Class".equals(qName)) {
        String role = getOptionalAttribute(attributes, "role");
        addMatcher(new ClassMatcher(getRequiredAttribute(attributes, "name", qName), role));
    } else if ("Type".equals(qName)) {
        String role = getOptionalAttribute(attributes, "role");
        String typeParameters = getOptionalAttribute(attributes, "typeParameters");
        addMatcher(new TypeMatcher(getRequiredAttribute(attributes, "descriptor", qName), role, typeParameters));
    } else if ("FirstVersion".equals(qName)) {
        addMatcher(new FirstVersionMatcher(getRequiredAttribute(attributes, "value", qName), getRequiredAttribute(attributes, "relOp", qName)));
    } else if ("LastVersion".equals(qName)) {
        addMatcher(new LastVersionMatcher(getRequiredAttribute(attributes, "value", qName), getRequiredAttribute(attributes, "relOp", qName)));
    } else if ("BugCode".equals(qName)) {
        addMatcher(new BugMatcher(getRequiredAttribute(attributes, "name", qName), "", ""));
    } else if ("Local".equals(qName)) {
        addMatcher(new LocalMatcher(getRequiredAttribute(attributes, "name", qName)));
    } else if ("BugPattern".equals(qName)) {
        addMatcher(new BugMatcher("", getRequiredAttribute(attributes, "name", qName), ""));
    } else if ("Priority".equals(qName)) {
        addMatcher(new PriorityMatcher(getRequiredAttribute(attributes, "value", qName)));
    } else if ("Confidence".equals(qName)) {
        addMatcher(new ConfidenceMatcher(getRequiredAttribute(attributes, "value", qName)));
    } else if ("Rank".equals(qName)) {
        addMatcher(new RankMatcher(getRequiredAttribute(attributes, "value", qName)));
    } else if ("Package".equals(qName)) {
        String pName = getRequiredAttribute(attributes, "name", qName);
        pName = pName.startsWith("~") ? pName : "~" + pName.replace(".", "\\.");
        addMatcher(new ClassMatcher(pName + "\\.[^.]+"));
    } else if ("Method".equals(qName)) {
        String name = getOptionalAttribute(attributes, "name");
        String params = getOptionalAttribute(attributes, "params");
        String returns = getOptionalAttribute(attributes, "returns");
        String role = getOptionalAttribute(attributes, "role");
        addMatcher(new MethodMatcher(name, params, returns, role));
    } else if ("Field".equals(qName)) {
        String name = getOptionalAttribute(attributes, "name");
        String type = getOptionalAttribute(attributes, "type");
        String role = getOptionalAttribute(attributes, "role");
        addMatcher(new FieldMatcher(name, type, role));
    } else if ("Or".equals(qName)) {
        CompoundMatcher matcher = new OrMatcher();
        pushCompoundMatcherAsChild(matcher);
    } else if ("And".equals(qName) || "Match".equals(qName)) {
        AndMatcher matcher = new AndMatcher();
        pushCompoundMatcherAsChild(matcher);
        if ("Match".equals(qName)) {
            String classregex = getOptionalAttribute(attributes, "classregex");
            String classMatch = getOptionalAttribute(attributes, "class");
            if (classregex != null) {
                addMatcher(new ClassMatcher("~" + classregex));
            } else if (classMatch != null) {
                addMatcher(new ClassMatcher(classMatch));
            }
        }
    } else if ("Not".equals(qName)) {
        NotMatcher matcher = new NotMatcher();
        pushCompoundMatcherAsChild(matcher);
    } else if ("Source".equals(qName)) {
        addMatcher(new SourceMatcher(getRequiredAttribute(attributes, "name", qName)));
    }
    nextMatchedIsDisabled = false;
}
Also used : CompoundMatcher(edu.umd.cs.findbugs.filter.CompoundMatcher) AndMatcher(edu.umd.cs.findbugs.filter.AndMatcher) ConfidenceMatcher(edu.umd.cs.findbugs.filter.ConfidenceMatcher) TypeMatcher(edu.umd.cs.findbugs.filter.TypeMatcher) ClassMatcher(edu.umd.cs.findbugs.filter.ClassMatcher) NotMatcher(edu.umd.cs.findbugs.filter.NotMatcher) OrMatcher(edu.umd.cs.findbugs.filter.OrMatcher) LocalMatcher(edu.umd.cs.findbugs.filter.LocalMatcher) RankMatcher(edu.umd.cs.findbugs.filter.RankMatcher) SourceMatcher(edu.umd.cs.findbugs.filter.SourceMatcher) BugMatcher(edu.umd.cs.findbugs.filter.BugMatcher) FirstVersionMatcher(edu.umd.cs.findbugs.filter.FirstVersionMatcher) PriorityMatcher(edu.umd.cs.findbugs.filter.PriorityMatcher) FieldMatcher(edu.umd.cs.findbugs.filter.FieldMatcher) LastVersionMatcher(edu.umd.cs.findbugs.filter.LastVersionMatcher) MethodMatcher(edu.umd.cs.findbugs.filter.MethodMatcher)

Aggregations

CompoundMatcher (edu.umd.cs.findbugs.filter.CompoundMatcher)2 AndMatcher (edu.umd.cs.findbugs.filter.AndMatcher)1 BugMatcher (edu.umd.cs.findbugs.filter.BugMatcher)1 ClassMatcher (edu.umd.cs.findbugs.filter.ClassMatcher)1 ConfidenceMatcher (edu.umd.cs.findbugs.filter.ConfidenceMatcher)1 FieldMatcher (edu.umd.cs.findbugs.filter.FieldMatcher)1 Filter (edu.umd.cs.findbugs.filter.Filter)1 FirstVersionMatcher (edu.umd.cs.findbugs.filter.FirstVersionMatcher)1 LastVersionMatcher (edu.umd.cs.findbugs.filter.LastVersionMatcher)1 LocalMatcher (edu.umd.cs.findbugs.filter.LocalMatcher)1 MethodMatcher (edu.umd.cs.findbugs.filter.MethodMatcher)1 NotMatcher (edu.umd.cs.findbugs.filter.NotMatcher)1 OrMatcher (edu.umd.cs.findbugs.filter.OrMatcher)1 PriorityMatcher (edu.umd.cs.findbugs.filter.PriorityMatcher)1 RankMatcher (edu.umd.cs.findbugs.filter.RankMatcher)1 SourceMatcher (edu.umd.cs.findbugs.filter.SourceMatcher)1 TypeMatcher (edu.umd.cs.findbugs.filter.TypeMatcher)1