/** * Resolves a type by its partial name within a given package context, following PB (== C++) * conventions. If the given name is a builtin type name for a primitive type in the PB * language, a reference for that type will be returned. * * Note that this differs from the proto compiler in that it will continue searching if a * partial resolution fails; see resolveType2 for details. */ @Nullable public TypeRef resolveType(String inPackage, String name) { TypeRef type = TypeRef.fromPrimitiveName(name); if (type != null) { return type; } for (String cand : nameCandidates(inPackage, name)) { type = lookupType(cand); if (type != null) { return type; } } return null; }
TypeRef type = lookupType(typeNamePattern); if (type == null) { return ImmutableList.of();
/** Helper to extract the types from the underlying model. */ private List<TypeRef> getTypes(Model model) { List<TypeRef> types = new ArrayList<>(); for (Type type : model.getServiceConfig().getTypesList()) { types.add(model.getSymbolTable().lookupType(type.getName())); } return types; }
/** * Resolves a type by its partial name within a given package context, following PB (== C++) * conventions. If the given name is a builtin type name for a primitive type in the PB * language, a reference for that type will be returned. * * Note that this differs from the proto compiler in that it will continue searching if a * partial resolution fails; see resolveType2 for details. */ @Nullable public TypeRef resolveType(String inPackage, String name) { TypeRef type = TypeRef.fromPrimitiveName(name); if (type != null) { return type; } for (String cand : nameCandidates(inPackage, name)) { type = lookupType(cand); if (type != null) { return type; } } return null; }
TypeRef outerType = lookupType(cand); if (outerType != null) { if (!outerType.isMessage()) { int lastDot = outerTypeName.lastIndexOf("."); String fullType = lastDot > 0 ? outerTypeName.substring(0, lastDot) + "." + name : name; return lookupType(fullType); } else if (packageNames.contains(cand)) { int lastDot = cand.lastIndexOf("."); String fullType = lastDot > 0 ? cand.substring(0, lastDot) + "." + name : name; return lookupType(fullType);
TypeRef type = lookupType(typeNamePattern); if (type == null) { return ImmutableList.of();
TypeRef outerType = lookupType(cand); if (outerType != null) { if (!outerType.isMessage()) { int lastDot = outerTypeName.lastIndexOf("."); String fullType = lastDot > 0 ? outerTypeName.substring(0, lastDot) + "." + name : name; return lookupType(fullType); } else if (packageNames.contains(cand)) { int lastDot = cand.lastIndexOf("."); String fullType = lastDot > 0 ? cand.substring(0, lastDot) + "." + name : name; return lookupType(fullType);
@BeforeClass public static void startUp() { Mockito.when(simpleMethod.getModel()).thenReturn(model); Mockito.when(lroAnnotatedMethod.getModel()).thenReturn(model); Mockito.when(model.getSymbolTable()).thenReturn(symbolTable); Mockito.when(protoParser.getProtoPackage(ArgumentMatchers.any(Method.class))) .thenReturn(PROTO_PACKAGE_NAME); Mockito.when(protoParser.getLongRunningOperation(lroAnnotatedMethod)) .thenReturn( OperationData.newBuilder() .setMetadataType(ANNOTATIONS_METADATA_TYPE) .setResponseType(ANNOTATIONS_RETURN_TYPE_NAME) .build()); Mockito.when(symbolTable.lookupType(PROTO_PACKAGE_NAME + "." + GAPIC_CONFIG_METADATA_TYPE)) .thenReturn(gapicConfigMetadataType); Mockito.when(symbolTable.lookupType(PROTO_PACKAGE_NAME + "." + GAPIC_CONFIG_RETURN_TYPE_NAME)) .thenReturn(gapicConfigReturnType); Mockito.when(symbolTable.lookupType(PROTO_PACKAGE_NAME + "." + ANNOTATIONS_METADATA_TYPE)) .thenReturn(annotationsMetadataType); Mockito.when(symbolTable.lookupType(PROTO_PACKAGE_NAME + "." + ANNOTATIONS_RETURN_TYPE_NAME)) .thenReturn(annotationsReturnType); }
/** * Returns the body type iff the body associates with exactly one message type. * Otherwise, returns null. */ @Nullable private TypeRef getSingleBodyType(Method method) { HttpAttribute httpConfig = method.getAttribute(HttpAttribute.KEY); if (httpConfig == null) { return null; } if (!httpConfig.bodyCapturesUnboundFields() && httpConfig.getBodySelectors().size() == 1) { TypeRef type = httpConfig.getBodySelectors().get(0).getType(); if (type.isMessage()) { // Get the TypeRef of the declared MessageType that is referenced in the body // selector field. // TODO(user): If it is common use pattern, consider moving it to where it belongs. return model.getSymbolTable().lookupType(type.getMessageType().getFullName()); } } return null; }
TypeRef type = lookupType(id); if (type != null) { if (type.isMessage()) {
if (!Strings.isNullOrEmpty(resourceName)) { TypeRef resourceType = field.getModel().getSymbolTable().lookupType(resourceName); if (resourceType != null) {
/** * Returns the body type iff the body associates with exactly one message type. * Otherwise, returns null. */ @Nullable private TypeRef getSingleBodyType(Method method) { HttpAttribute httpConfig = method.getAttribute(HttpAttribute.KEY); if (httpConfig == null) { return null; } if (!httpConfig.bodyCapturesUnboundFields() && httpConfig.getBodySelectors().size() == 1) { TypeRef type = httpConfig.getBodySelectors().get(0).getType(); if (type.isMessage()) { // Get the TypeRef of the declared MessageType that is referenced in the body // selector field. // TODO(user): If it is common use pattern, consider moving it to where it belongs. return model.getSymbolTable().lookupType(type.getMessageType().getFullName()); } } return null; }
TypeRef type = lookupType(id); if (type != null) { if (type.isMessage()) {
private void addExtraExtensionTypes() { for (String optionType : foundOptionTypes) { if (isWhitelistedExtensionType(optionType)) { TypeRef typeRef = symbolTable.lookupType(optionType); if (null != typeRef) { ProtoElement element = null; if (typeRef.isMessage()) { element = typeRef.getMessageType(); } else if (typeRef.isEnum()) { element = typeRef.getEnumType(); } if (null != element) { model.addRoot(element); } } } } }
private void addExtraExtensionTypes() { for (String optionType : foundOptionTypes) { if (isWhitelistedExtensionType(optionType)) { TypeRef typeRef = symbolTable.lookupType(optionType); if (null != typeRef) { ProtoElement element = null; if (typeRef.isMessage()) { element = typeRef.getMessageType(); } else if (typeRef.isEnum()) { element = typeRef.getEnumType(); } if (null != element) { model.addRoot(element); } } } } }
TypeRef returnType = model.getSymbolTable().lookupType(responseTypeName); TypeRef metadataType = model.getSymbolTable().lookupType(metadataTypeName);
private void assertTypeInclusions(Model model, Iterable<String> includedTypeNames, Iterable<String> excludedTypeNames) { for (String typeName : includedTypeNames) { TypeRef type = model.getSymbolTable().lookupType(typeName); Assert.assertNotNull(type); Assert.assertTrue(type.isMessage() || type.isEnum()); if (type.isMessage()) { Assert.assertTrue(type.getMessageType().isReachable()); } else { Assert.assertTrue(type.getEnumType().isReachable()); } } for (String typeName : excludedTypeNames) { TypeRef type = model.getSymbolTable().lookupType(typeName); Assert.assertNotNull(type); Assert.assertTrue(type.isMessage() || type.isEnum()); if (type.isMessage()) { Assert.assertFalse(type.getMessageType().isReachable()); } else { Assert.assertFalse(type.getEnumType().isReachable()); } } }
TypeRef returnType = model.getSymbolTable().lookupType(longRunningConfigProto.getReturnType()); TypeRef metadataType = model.getSymbolTable().lookupType(longRunningConfigProto.getMetadataType());