| 1 | = Type entity = |
| 2 | |
| 3 | Type entities can represent ''-type'', ''-opaque'' attributes(user-defined types), built-in types or any type expression in an erlang file. Please note that type expressions consisting of only a single atom(e.g.: ok, 'error') are filtered from the results of any selector that returns type entities. |
| 4 | |
| 5 | == Initial selector == |
| 6 | When a type expression is indicated by the given position, the {{{@type}}} initial-selector can be used to return the corresponding type entity. |
| 7 | |
| 8 | == Selectors == |
| 9 | |
| 10 | ''The type of the result elements are indicated in parenthesis.'' |
| 11 | |
| 12 | * {{{file}}} (''file''): The defining file of the type. |
| 13 | * {{{arguments}}} (''type''): The arguments of the type. |
| 14 | * {{{subtypes}}} (''type''): Subtypes of the given type. |
| 15 | * {{{specref}}} (''spec''): Specs using this type. |
| 16 | * {{{references}}} (''type''): The references of the type. |
| 17 | * {{{paramsref}}} (''type''): The references of the types arguments. |
| 18 | |
| 19 | == Properties == |
| 20 | |
| 21 | The following properties are defined for spec entities: |
| 22 | |
| 23 | * {{{name}}} (''atom''): The name of the type |
| 24 | * {{{arity}}} (''int''): The arity of the type. |
| 25 | * {{{exported}}} (''bool''): Returns whether the type is exported. |
| 26 | * {{{opaque}}} (''bool''): Returns whether the type is opaque. |
| 27 | * {{{builtin}}} (''bool''): Returns whether the type is built-in. |
| 28 | |
| 29 | == Textual output format == |
| 30 | |
| 31 | When using any of our interfaces, other than ris?, this entity will be represented in the output as a string with the following possible formats: |
| 32 | |
| 33 | * When the entity represents a user-defined or built-in type: |
| 34 | {{{ |
| 35 | Type -> string (Module:Name/Arity) |
| 36 | Module -> atom (defining module of the type) |
| 37 | Name -> atom (name of the type = Type.name) |
| 38 | Arity -> int (number of parameters of the type = Type.arity) |
| 39 | }}} |
| 40 | |
| 41 | * When the entity represents a type expression: |
| 42 | {{{ |
| 43 | Type -> string (textual representation of the type expression, as it was formatted in the source) |
| 44 | }}} |
| 45 | |
| 46 | == Review of non-trivial selectors == |
| 47 | Due to the multiple structures represented by this entity, some of the selectors have a complex specification. These are described below: |
| 48 | |
| 49 | === Type.arguments: === |
| 50 | Returns the type or type expression of the given type's parameters. |
| 51 | {{{ |
| 52 | %%-type myt(Key, Val) :: myt(Key, ok). |
| 53 | ri:q("mods.types.params"). |
| 54 | a:myt/2 |
| 55 | Key |
| 56 | Val |
| 57 | ok |
| 58 | ri:q("mods.types.subtypes.params"). |
| 59 | myt(Key, ok) |
| 60 | Key |
| 61 | }}} |
| 62 | |
| 63 | === Type.subtypes: === |
| 64 | If the given type is a user-defined type it returns the type's body as a type expression. When the given type is a type expression it returns the expression's subexpressions(1-level deep). |
| 65 | {{{ |
| 66 | ri:q("mods.types.subtypes"). |
| 67 | a:prp_user/2 |
| 68 | [{atom(), Key, Val}] |
| 69 | a:myt/2 |
| 70 | myt(Key, ok) |
| 71 | ok |
| 72 | ri:q("mods.types.subtypes.subtypes"). |
| 73 | [{atom(), Key, Val}] |
| 74 | {atom(), Key, Val} |
| 75 | myt(Key, ok) |
| 76 | Key |
| 77 | }}} |
| 78 | |
| 79 | === Type.specrefs: === |
| 80 | For user-defined and built-in types, returns the specs referencing this type. |
| 81 | {{{ |
| 82 | ri:q("mods.types.specrefs"). |
| 83 | b:prp_user/2 |
| 84 | -spec g(prp_user(X,Y))->'ok'. |
| 85 | }}} |
| 86 | |
| 87 | === Type.references: === |
| 88 | Returns the type expressions using this user-defined or built-in type. If the given type is a type expression it tries to find the user-defined or built-in type referenced in the type expression and continues from there. Otherwise the result is empty. |
| 89 | {{{ |
| 90 | ri:q("mods.types.refs"). |
| 91 | b:prp_user/2 |
| 92 | prp_user(X,Y) |
| 93 | a:myt/2 |
| 94 | myt(list(), ok) |
| 95 | myt(Key, ok) |
| 96 | }}} |