Search in sources :

Example 1 with TypeCriteria

use of org.sonar.java.matcher.TypeCriteria in project sonar-java by SonarSource.

the class ImmediateReverseBoxingCheck method unboxingInvocationMatchers.

private static MethodMatcherCollection unboxingInvocationMatchers() {
    MethodMatcherCollection matchers = MethodMatcherCollection.create();
    for (Entry<String, String> type : PRIMITIVE_TYPES_BY_WRAPPER.entrySet()) {
        String primitiveType = type.getValue();
        TypeCriteria typeCriteria;
        if ("char".equals(primitiveType) || "boolean".equals(primitiveType)) {
            typeCriteria = TypeCriteria.is(type.getKey());
        } else {
            typeCriteria = TypeCriteria.subtypeOf("java.lang.Number");
        }
        matchers.add(MethodMatcher.create().callSite(typeCriteria).name(primitiveType + "Value").withoutParameter());
    }
    return matchers;
}
Also used : TypeCriteria(org.sonar.java.matcher.TypeCriteria) MethodMatcherCollection(org.sonar.java.matcher.MethodMatcherCollection)

Aggregations

MethodMatcherCollection (org.sonar.java.matcher.MethodMatcherCollection)1 TypeCriteria (org.sonar.java.matcher.TypeCriteria)1