/** * Returns true if this is a primitive type. */ public boolean isPrimitive() { return !isMessage() && !isEnum(); }
/** * Returns true if this is a primitive type. */ public boolean isPrimitive() { return !isMessage() && !isEnum(); }
@Override public boolean isEnum() { return getProtoType().isEnum(); }
@Override public boolean isEnum() { return protoField.getType().isEnum(); }
@Override public boolean apply(TypeRef type) { if (type.getKind() == kind) { if (type.isMessage()) { return type.getMessageType().getFullName().startsWith( typeNamePattern.substring(0, typeNamePattern.length() - 1)); } else if (type.isEnum()) { return type.getEnumType().getFullName().startsWith( typeNamePattern.substring(0, typeNamePattern.length() - 1)); } return false; } return false; } })
@Override public boolean apply(TypeRef type) { if (type.getKind() == kind) { if (type.isMessage()) { return type.getMessageType().getFullName().startsWith( typeNamePattern.substring(0, typeNamePattern.length() - 1)); } else if (type.isEnum()) { return type.getEnumType().getFullName().startsWith( typeNamePattern.substring(0, typeNamePattern.length() - 1)); } return false; } return false; } })
private boolean packageHasEnums(Model model) { for (TypeRef type : model.getSymbolTable().getDeclaredTypes()) { if (type.isEnum() && type.getEnumType().isReachable()) { return true; } } return false; }
@Override public String getTypeNameDoc(ImportTypeTable typeTable, TypeModel typeModel) { TypeRef typeRef = ((ProtoTypeRef) typeModel).getProtoType(); if (typeRef.isMessage()) { return "an object representing " + commentReformatter.getLinkedElementName(typeRef.getMessageType()); } else if (typeRef.isEnum()) { return "a number of " + commentReformatter.getLinkedElementName(typeRef.getEnumType()); } // Converting to lowercase because "String" is capitalized in NodeJSModelTypeNameConverter. return "a " + getParamTypeNoCardinality(typeTable, typeModel).toLowerCase(); }
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); } } } } }
@Visits void reach(MessageType message) { markAsReachable(message); visitInScope(message.getFields()); // Check whether required fields are hidden, and whether the message has unreachable // descendants. for (Field field : message.getFields()) { if (!isReachable(field)) { hasUnreachableDescendants.add(message); if (field.isRequired()) { error(field, "A required field cannot be hidden. %s.", reasonForUnreachable(field)); } } else { TypeRef type = field.getType(); if (type.isMessage() && hasUnreachableDescendants(type.getMessageType()) || type.isEnum() && hasUnreachableDescendants(type.getEnumType())) { hasUnreachableDescendants.add(message); } } } }
@Override public TypedValue getSnippetZeroValue(TypeRef type) { // Don't call getTypeName; we don't need to import these. if (type.isMap()) { return TypedValue.create(new TypeName("dict"), "{}"); } if (type.isRepeated()) { return TypedValue.create(new TypeName("list"), "[]"); } if (PRIMITIVE_ZERO_VALUE.containsKey(type.getKind())) { return TypedValue.create(getTypeName(type), PRIMITIVE_ZERO_VALUE.get(type.getKind())); } if (type.isMessage()) { return TypedValue.create(getTypeName(type), "{}"); } if (type.isEnum()) { return getEnumValue(type, type.getEnumType().getValues().get(0)); } return TypedValue.create(new TypeName(""), "None"); }
@Visits void reach(MessageType message) { markAsReachable(message); visitInScope(message.getFields()); // Check whether required fields are hidden, and whether the message has unreachable // descendants. for (Field field : message.getFields()) { if (!isReachable(field)) { hasUnreachableDescendants.add(message); if (field.isRequired()) { error(field, "A required field cannot be hidden. %s.", reasonForUnreachable(field)); } } else { TypeRef type = field.getType(); if (type.isMessage() && hasUnreachableDescendants(type.getMessageType()) || type.isEnum() && hasUnreachableDescendants(type.getEnumType())) { hasUnreachableDescendants.add(message); } } } }
/** * Returns the Java representation of a zero value for that type, to be used in code sample doc. * * <p>Parametric types may use the diamond operator, since the return value will be used only in * initialization. */ @Override public TypedValue getSnippetZeroValue(TypeRef type) { // Don't call importAndGetShortestName; we don't need to import these. if (type.isMap()) { return TypedValue.create(typeNameConverter.getTypeName("java.util.HashMap"), "new %s<>()"); } if (type.isRepeated()) { return TypedValue.create(typeNameConverter.getTypeName("java.util.ArrayList"), "new %s<>()"); } if (PRIMITIVE_ZERO_VALUE.containsKey(type.getKind())) { return TypedValue.create(getTypeName(type), PRIMITIVE_ZERO_VALUE.get(type.getKind())); } if (type.isMessage()) { return TypedValue.create(getTypeName(type), "%s.newBuilder().build()"); } if (type.isEnum()) { return getEnumValue(type, type.getEnumType().getValues().get(0)); } return TypedValue.create(getTypeName(type), "null"); }
/** * Returns the PHP representation of a zero value for that type, to be used in code sample doc. */ @Override public TypedValue getSnippetZeroValue(TypeRef type) { // Don't call getTypeName; we don't need to import these. if (type.isMap()) { return TypedValue.create(new TypeName("array"), "[]"); } if (type.isRepeated()) { return TypedValue.create(new TypeName("array"), "[]"); } if (PRIMITIVE_ZERO_VALUE.containsKey(type.getKind())) { return TypedValue.create(getTypeName(type), PRIMITIVE_ZERO_VALUE.get(type.getKind())); } if (type.isMessage()) { return TypedValue.create(getTypeName(type), "new %s()"); } if (type.isEnum()) { return getEnumValue(type, type.getEnumType().getValues().get(0)); } return TypedValue.create(new TypeName(""), "null"); }
/** * Returns the Ruby representation of a zero value for that type, to be used in code sample doc. */ @Override public TypedValue getSnippetZeroValue(TypeRef type) { // Don't call getTypeName; we don't need to import these. if (type.isMap()) { return TypedValue.create(new TypeName("Hash"), "{}"); } if (type.isRepeated()) { return TypedValue.create(new TypeName("Array"), "[]"); } if (PRIMITIVE_ZERO_VALUE.containsKey(type.getKind())) { return TypedValue.create(getTypeName(type), PRIMITIVE_ZERO_VALUE.get(type.getKind())); } if (type.isMessage()) { TypeName typeName = getTypeName(type); return TypedValue.create(typeName, "{}"); } if (type.isEnum()) { return getEnumValue(type, type.getEnumType().getValues().get(0)); } return TypedValue.create(new TypeName(""), "nil"); }
private void addApiImports(GapicInterfaceContext context) { for (TypeRef type : context.getInterface().getModel().getSymbolTable().getDeclaredTypes()) { if (type.isEnum() && type.getEnumType().isReachable()) { context.getImportTypeTable().getAndSaveNicknameFor(type); break; } } for (MethodModel method : context.getSupportedMethods()) { addMethodImports(context.asDynamicMethodContext(method)); } }
private void addApiImports(GapicInterfaceContext context) { for (TypeRef type : context.getInterface().getModel().getSymbolTable().getDeclaredTypes()) { if (type.isEnum() && type.getEnumType().isReachable()) { context.getImportTypeTable().getAndSaveNicknameFor(type); break; } } for (MethodModel method : context.getSupportedMethods()) { addMethodImports(context.asDynamicMethodContext(method)); } }
@Visits void reach(Field field) { TypeRef type = field.getType(); if (type.isMap()) { visitInScope(type.getMessageType()); if (type.getMapValueField().getType().isMessage()) { // Be sure to generate error message only for the value type, not for the internal // key-value message. However, the later needs to be included, therefore we did // visitInScope above. mustBeInScope(field, type.getMapValueField().getType().getMessageType()); } } else if (type.isMessage()) { mustBeInScope(field, type.getMessageType()); } else if (type.isEnum()) { mustBeInScope(field, type.getEnumType()); } markAsReachable(field); }
@Visits void reach(Field field) { TypeRef type = field.getType(); if (type.isMap()) { visitInScope(type.getMessageType()); if (type.getMapValueField().getType().isMessage()) { // Be sure to generate error message only for the value type, not for the internal // key-value message. However, the later needs to be included, therefore we did // visitInScope above. mustBeInScope(field, type.getMapValueField().getType().getMessageType()); } } else if (type.isMessage()) { mustBeInScope(field, type.getMessageType()); } else if (type.isEnum()) { mustBeInScope(field, type.getEnumType()); } markAsReachable(field); }