private static boolean isProtoRepeatedFieldCountMethod(ExpressionTree tree, VisitorState state) { // Instance method, on proto class, named `get<Field>Count`. if (!PROTO_METHOD_NAMED_GET_COUNT.matches(tree, state)) { return false; } // Make sure it's the count method for a repeated field, not the get method for a non-repeated // field named <something>_count, by checking for other methods on the repeated field. MethodSymbol methodCallSym = getSymbol((MethodInvocationTree) tree); if (methodCallSym == null) { return false; } Scope protoClassMembers = methodCallSym.owner.members(); java.util.regex.Matcher getCountRegexMatcher = PROTO_COUNT_METHOD_PATTERN.matcher(methodCallSym.getSimpleName().toString()); if (!getCountRegexMatcher.matches()) { return false; } String fieldName = getCountRegexMatcher.group(1); return protoClassMembers.findFirst(state.getName("get" + fieldName + "List")) != null; }
private static boolean isProtoRepeatedFieldCountMethod(ExpressionTree tree, VisitorState state) { // Instance method, on proto class, named `get<Field>Count`. if (!PROTO_METHOD_NAMED_GET_COUNT.matches(tree, state)) { return false; } // Make sure it's the count method for a repeated field, not the get method for a non-repeated // field named <something>_count, by checking for other methods on the repeated field. MethodSymbol methodCallSym = getSymbol((MethodInvocationTree) tree); if (methodCallSym == null) { return false; } Scope protoClassMembers = methodCallSym.owner.members(); java.util.regex.Matcher getCountRegexMatcher = PROTO_COUNT_METHOD_PATTERN.matcher(methodCallSym.getSimpleName().toString()); if (!getCountRegexMatcher.matches()) { return false; } String fieldName = getCountRegexMatcher.group(1); return protoClassMembers.findFirst(state.getName("get" + fieldName + "List")) != null; }