Skip to content

Commit c13335f

Browse files
wojtekmachjosevalim
authored andcommitted
Add Module.reserved_attributes/0 (#10926)
1 parent d85d13f commit c13335f

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

lib/elixir/lib/module.ex

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ defmodule Module do
335335
@vsn "1.0"
336336
end
337337
338+
### Struct attributes
339+
340+
* `@derive` - derives an implementation for the given protocol for the
341+
struct defined in the current module
342+
343+
* `@enforce_keys` - ensures the given keys are always set when building
344+
the struct defined in the current module
345+
346+
See `Kernel.defstruct/1` for more information on building and using structs.
347+
338348
### Typespec attributes
339349
340350
The following attributes are part of typespecs and are also built-in in
@@ -543,6 +553,103 @@ defmodule Module do
543553
@callback __info__(:md5) :: binary()
544554
@callback __info__(:module) :: module()
545555

556+
@doc """
557+
Returns information about module attributes used by Elixir.
558+
559+
See the "Module attributes" section in the module documentation for more
560+
information on each attribute.
561+
562+
## Examples
563+
564+
iex> map = Module.reserved_attributes()
565+
iex> Map.has_key?(map, :moduledoc)
566+
true
567+
iex> Map.has_key?(map, :doc)
568+
true
569+
570+
"""
571+
@doc since: "1.12.0"
572+
def reserved_attributes() do
573+
%{
574+
after_compile: %{
575+
doc: "A hook that will be invoked right after the current module is compiled."
576+
},
577+
before_compile: %{
578+
doc: "A hook that will be invoked before the module is compiled."
579+
},
580+
behaviour: %{
581+
doc: "Specifies that the current module implements a given behaviour."
582+
},
583+
on_definition: %{
584+
doc:
585+
"A hook that will be invoked when each function or macro in the current module is defined."
586+
},
587+
impl: %{
588+
doc: "Declares an implementation of a callback function or macro."
589+
},
590+
compile: %{
591+
doc: "Defines options for module compilation."
592+
},
593+
deprecated: %{
594+
doc: "Provides the deprecation reason for a function."
595+
},
596+
moduledoc: %{
597+
doc: "Provides documentation for the current module."
598+
},
599+
doc: %{
600+
doc: "Provides documentation for a function/macro/callback."
601+
},
602+
typedoc: %{
603+
doc: "Provides documentation for a type."
604+
},
605+
dialyzer: %{
606+
doc: "Defines Dialyzer warnings to request or suppress."
607+
},
608+
external_resource: %{
609+
doc: "Specifies an external resource for the current module."
610+
},
611+
file: %{
612+
doc:
613+
"Changes the filename used in stacktraces for the function or macro that follows the attribute."
614+
},
615+
on_load: %{
616+
doc: "A hook that will be invoked whenever the module is loaded."
617+
},
618+
vsn: %{
619+
doc: "Specify the module version."
620+
},
621+
type: %{
622+
doc: "Defines a type to be used in `@spec`."
623+
},
624+
typep: %{
625+
doc: "Defines a private type to be used in `@spec`."
626+
},
627+
opaque: %{
628+
doc: "Defines an opaque type to be used in `@spec`."
629+
},
630+
spec: %{
631+
doc: "Provides a specification for a function."
632+
},
633+
callback: %{
634+
doc: "Provides a specification for a behaviour callback."
635+
},
636+
macrocallback: %{
637+
doc: "Provides a specification for a macro behaviour callback."
638+
},
639+
optional_callbacks: %{
640+
doc: "Specifies which behaviour callbacks and macro behaviour callbacks are optional."
641+
},
642+
derive: %{
643+
doc:
644+
"Derives an implementation for the given protocol for the struct defined in the current module."
645+
},
646+
enforce_keys: %{
647+
doc:
648+
"Ensures the given keys are always set when building the struct defined in the current module."
649+
}
650+
}
651+
end
652+
546653
@doc """
547654
Checks if a module is open.
548655

0 commit comments

Comments
 (0)