Type entity
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.
Initial selector
When a type expression is indicated by the given position, the @type initial-selector can be used to return the corresponding type entity.
Selectors
The type of the result elements are indicated in parenthesis.
- file (file): The defining file of the type.
- arguments (type): The arguments of the type.
- subtypes (type): Subtypes of the given type.
- specref (spec): Specs using this type.
- references (type): The references of the type.
- paramsref (type): The references of the types arguments.
Properties
The following properties are defined for spec entities:
- name (atom): The name of the type
- arity (int): The arity of the type.
- exported (bool): Returns whether the type is exported.
- opaque (bool): Returns whether the type is opaque.
- builtin (bool): Returns whether the type is built-in.
Textual output format
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:
- When the entity represents a user-defined or built-in type:
Type -> string (Module:Name/Arity) Module -> atom (defining module of the type) Name -> atom (name of the type = Type.name) Arity -> int (number of parameters of the type = Type.arity)
- When the entity represents a type expression:
Type -> string (textual representation of the type expression, as it was formatted in the source)
Review of non-trivial selectors
Due to the multiple structures represented by this entity, some of the selectors have a complex specification. These are described below:
Type.arguments:
Returns the type or type expression of the given type's parameters.
%%-type myt(Key, Val) :: myt(Key, ok). ri:q("mods.types.params"). a:myt/2 Key Val ok ri:q("mods.types.subtypes.params"). myt(Key, ok) Key
Type.subtypes:
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).
ri:q("mods.types.subtypes"). a:prp_user/2 [{atom(), Key, Val}] a:myt/2 myt(Key, ok) ok ri:q("mods.types.subtypes.subtypes"). [{atom(), Key, Val}] {atom(), Key, Val} myt(Key, ok) Key
Type.specrefs:
For user-defined and built-in types, returns the specs referencing this type.
ri:q("mods.types.specrefs"). b:prp_user/2 -spec g(prp_user(X,Y))->'ok'.
Type.references:
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.
ri:q("mods.types.refs"). b:prp_user/2 prp_user(X,Y) a:myt/2 myt(list(), ok) myt(Key, ok)