Pruner(Schema schema, IdentifierSet identifierSet) { this.schema = schema; this.identifierSet = identifierSet; this.marks = new MarkSet(identifierSet); this.queue = new ArrayDeque<>(); }
Rpc retainAll(Schema schema, MarkSet markSet) { if (!markSet.contains(requestType) || !markSet.contains(responseType)) return null; Rpc result = new Rpc(location, name, documentation, requestTypeElement, responseTypeElement, requestStreaming, responseStreaming, options.retainAll(schema, markSet)); result.requestType = requestType; result.responseType = responseType; return result; }
private void markEnum(EnumType wireEnum) { markOptions(wireEnum.options()); if (marks.containsAllMembers(wireEnum.type())) { for (EnumConstant constant : wireEnum.constants()) { if (marks.contains(ProtoMember.get(wireEnum.type(), constant.name()))) { markOptions(constant.options()); } } } }
private void markRoots(ProtoMember protoMember) { if (identifierSet.includes(protoMember)) { marks.root(protoMember); queue.add(protoMember); } }
private void mark(ProtoMember protoMember) { if (marks.mark(protoMember)) { queue.add(protoMember); // The transitive dependencies of this member must be visited. } }
private void markType(Type type) { markOptions(type.options()); if (marks.containsAllMembers(type.type())) { if (type instanceof MessageType) { markMessage((MessageType) type); } else if (type instanceof EnumType) { markEnum((EnumType) type); } } }
private void markRoots(Service service) { ProtoType protoType = service.type(); if (identifierSet.includes(protoType)) { marks.root(protoType); queue.add(protoType); } else { for (Rpc rpc : service.rpcs()) { markRoots(ProtoMember.get(protoType, rpc.name())); } } }
private void mark(ProtoType type) { // Mark the map type as it's non-scalar and transitively reachable. if (type.isMap()) { marks.mark(type); // Map key type is always scalar. No need to mark it. type = type.valueType(); } if (marks.mark(type)) { queue.add(type); // The transitive dependencies of this type must be visited. } }
private void markService(Service service) { markOptions(service.options()); if (marks.containsAllMembers(service.type())) { for (Rpc rpc : service.rpcs()) { markRpc(service.type(), rpc); } } }
static ImmutableList<Field> retainAll( Schema schema, MarkSet markSet, ProtoType enclosingType, Collection<Field> fields) { ImmutableList.Builder<Field> result = ImmutableList.builder(); for (Field field : fields) { Field retainedField = field.retainAll(schema, markSet); if (retainedField != null && markSet.contains(ProtoMember.get(enclosingType, field.name()))) { result.add(retainedField); } } return result.build(); }
private void markEnum(EnumType wireEnum) { markOptions(wireEnum.options()); if (marks.containsAllMembers(wireEnum.type())) { for (EnumConstant constant : wireEnum.constants()) { if (marks.contains(ProtoMember.get(wireEnum.type(), constant.name()))) { markOptions(constant.options()); } } } }
private void markRoots(Type type) { ProtoType protoType = type.type(); if (identifierSet.includes(protoType)) { marks.root(protoType); queue.add(protoType); } else { if (type instanceof MessageType) { for (Field field : ((MessageType) type).fieldsAndOneOfFields()) { markRoots(ProtoMember.get(protoType, field.name())); } } else if (type instanceof EnumType) { for (EnumConstant enumConstant : ((EnumType) type).constants()) { markRoots(ProtoMember.get(protoType, enumConstant.name())); } } else { throw new AssertionError(); } } for (Type nested : type.nestedTypes()) { markRoots(nested); } }
private void mark(ProtoMember protoMember) { if (marks.mark(protoMember)) { queue.add(protoMember); // The transitive dependencies of this member must be visited. } }
private void markType(Type type) { markOptions(type.options()); if (marks.containsAllMembers(type.type())) { if (type instanceof MessageType) { markMessage((MessageType) type); } else if (type instanceof EnumType) { markEnum((EnumType) type); } } }
public Pruner(Schema schema, IdentifierSet identifierSet) { this.schema = schema; this.identifierSet = identifierSet; this.marks = new MarkSet(identifierSet); this.queue = new ArrayDeque<>(); }
@Override Type retainAll(Schema schema, MarkSet markSet) { // If this type is not retained, prune it. if (!markSet.contains(protoType)) return null; ImmutableList.Builder<EnumConstant> retainedConstants = ImmutableList.builder(); for (EnumConstant constant : constants) { if (markSet.contains(ProtoMember.get(protoType, constant.name()))) { retainedConstants.add(constant.retainAll(schema, markSet)); } } EnumType result = new EnumType(protoType, location, documentation, name, retainedConstants.build(), options.retainAll(schema, markSet)); result.allowAlias = allowAlias; return result; }
private void markEnum(EnumType wireEnum) { markOptions(wireEnum.options()); if (marks.containsAllMembers(wireEnum.type())) { for (EnumConstant constant : wireEnum.constants()) { if (marks.contains(ProtoMember.get(wireEnum.type(), constant.name()))) { markOptions(constant.options()); } } } }
private void markRoots(ProtoMember protoMember) { if (identifierSet.includes(protoMember)) { marks.root(protoMember); queue.add(protoMember); } }
private void mark(ProtoMember protoMember) { if (marks.mark(protoMember)) { queue.add(protoMember); // The transitive dependencies of this member must be visited. } }
private void markType(Type type) { markOptions(type.options()); if (marks.containsAllMembers(type.type())) { if (type instanceof MessageType) { markMessage((MessageType) type); } else if (type instanceof EnumType) { markEnum((EnumType) type); } } }